/    Sign up×
Community /Pin to ProfileBookmark

displaying columms

Ok

I have a search html forms where people will select what they are looking for

for example if they select the state of MA and The city of Andover and a business category.

the problem that i am having is that it seems that it is jumping the code because i have everything i need but

this are the code

[code=php]
<?
$host = “localhost”;
$username = “localhost”;
$password = “abc123”;
$database = “contacts”;

$db = mysql_connect($host, $username, $password);
mysql_select_db($database);

$result=mysql_query($query);

$Categories = addslashes($Categories);
$Categories = addslashes($Categories);

$query = “select * from Categories where “.$Categories.” like ‘%”.$Categories.”%'”;
$result = mysql_query($query);

echo “<p>Number of business found: “.$num_result.”</p>”;

for ($i=0; $i <$num_result; $i++)
{
$row = mysql_fetch_array($result);
echo “<p><strong>”.($i+1).”.BusinessName “;
echo ($row[“.$Slogan.”]);
echo “</strong><br>Address “;
echo (stripslashes($row[“Business_Address”]));
echo “<br>ISBN: “;
echo (stripslashes($row[“Make”]));
echo “<br>State: “;
echo (stripslashes($row[“type”]));
echo “<br>Price: “;
echo (stripslashes($row[“Tel”]));
echo “</p>”;
}
if(!$Categories)

{

echo “No Categories found.”;

exit;
}

?>
[/code]

help please

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJun 12.2006 — Ita messy, you have bits of code doing nothing or two times? and have left out vital peices
[code=php]
<?php

$host = "localhost";
$username = "localhost";
$password = "abc123";
$database = "contacts";

$db = mysql_connect($host, $username, $password);
mysql_select_db($database);


$Categories = addslashes($Categories);//where are you settign this?
$Categories = addslashes($Categories);//or this?
//and why two times?


$query = "SELECT * Categories WHERE ".$Categories." LIKE '%".$Categories."%'";
$result = mysql_query($query) or die (mysql_error());
//add some error checking


echo "<p>Number of business found: ".$num_result."</p>"; // where have you set this num result?

for ($i=0; $i <$num_result; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).".BusinessName ";
echo ($row[".$Slogan."]); //huh? why a $?
echo "</strong><br>Address ";
echo (stripslashes($row["Business_Address"]));
echo "<br>ISBN: ";
echo (stripslashes($row["Make"]));
echo "<br>State: ";
echo (stripslashes($row["type"]));
echo "<br>Price: ";
echo (stripslashes($row["Tel"]));
echo "</p>";
}
if(!$Categories)

{

echo "No Categories found.";

exit;
}


?>
[/code]


try some thing like this

[code=php]
<?php

$host = "localhost";
$username = "localhost";
$password = "abc123";
$database = "contacts";

$db = mysql_connect($host, $username, $password);
mysql_select_db($database);

if(isset($_GET['Categories']))
{
$Categories = addslashes($_GET['Categories']);
}else{
echo("No Categories found.");
exit;
}


$query = "SELECT * Categories WHERE ".$Categories." LIKE '%".$Categories."%'";
$result = mysql_query($query) or die (mysql_error());
$num_result = mysql_num_rows($result);


if($num_result <= 0)
{
echo("No Results found.");
exit;
}

echo("<p>Number of business found: ".$num_result."</p>";
while($row = mysql_fetch_array($result))
{

echo "<p><strong>BusinessName ";
echo ($row["Slogan"]);
echo "</strong><br>Address ";
echo (stripslashes($row["Business_Address"]));
echo "<br>ISBN: ";
echo (stripslashes($row["Make"]));
echo "<br>State: ";
echo (stripslashes($row["type"]));
echo "<br>Price: ";
echo (stripslashes($row["Tel"]));
echo "</p>";
}

?>
[/code]
Copy linkTweet thisAlerts:
@franknuauthorJun 12.2006 — I am getting " no categories found" I have data inside categories, i dont know why it is not grabbin the message thank you
[code=php]
<?php

$host = "localhost";
$username = "localhost";
$password = "abc123";
$database = "contacts";

$db = mysql_connect($host, $username, $password);
mysql_select_db($database);

if(isset($_GET['Categories']))
{
$Categories = addslashes($_GET['Categories']);
}else{
echo("No Categories found.");
exit;
}


$query = "SELECT * Categories WHERE ".$Categories." LIKE '%".$Categories."%'";
$result = mysql_query($query) or die (mysql_error());
$num_result = mysql_num_rows($result);


if($num_result <= 0)
{
echo("No Results found.");
exit;
}

echo "<p>Number of business found: ".$num_result."</p>";
while($row = mysql_fetch_array($result))
{

echo "<p><strong>BusinessName ";
echo ($row["Slogan"]);
echo "</strong><br>Address ";
echo (stripslashes($row["Business_Address"]));
echo "<br>ISBN: ";
echo (stripslashes($row["Make"]));
echo "<br>State: ";
echo (stripslashes($row["type"]));
echo "<br>Price: ";
echo (stripslashes($row["Tel"]));
echo "</p>";
}

?>
[/code]
Copy linkTweet thisAlerts:
@SheldonJun 13.2006 — are you setting $categories ?

call the page like this

http://localhost/pagename.php?Categories=*search_here*

also i dont no is this is the correct query
[code=php]
$query = "SELECT * Categories WHERE ".$Categories." LIKE '%".$Categories."%'"; [/code]
Copy linkTweet thisAlerts:
@franknuauthorJun 14.2006 — well i did that http://www.mass-ad.com/freedisplay2.php?Categories=*automotive*

i still keep gettin the same message

i also made some changes to the php

[code=php]

<?php

$host = "localhost";
$username = "localhost";
$password = "abc123";
$database = "contacts";


trim($Categories,$make,$type);
if(!$Categories||!$make||$type)

$Categories = addslashes ($Categoreis);
$make = addslashes ($make);
$type = addslashes ($type);

{
echo "You have not enter all fields";
exit;
}


$db = mysql_connect($host, $username, $password);
mysql_select_db($database);

if(isset($_GET['Categories']))
{
$Categories = addslashes($_GET['Categories']);
}
else

{
echo("No Categories found.");
exit;
}


$query = "SELECT * FROM Categories WHERE Categories LIKE '%".$Categories."%'";
$result = mysql_query($query) or die (mysql_error());
$num_result = mysql_num_rows($result);


if($num_result <= 0)
{
echo("No Results found.");
exit;
}

echo "<p>Number of business found: ".$num_result."</p>";
while($row = mysql_fetch_array($result))
{

echo "<p><strong>BusinessName ";
echo (stripslahes($row["<strong>BusinessNama"]));
echo ($row["Slogan"]);
echo "</strong><br>Address ";
echo (stripslashes($row["Business_Address"]));
echo "<br>State ";
echo (stripslashes($row["Make"]));
echo "<br>City ";
echo (stripslashes($row["type"]));
echo "<br>Tel ";
echo (stripslashes($row["Tel"]));
echo "</p>";
}

?>

[/code]


help please
Copy linkTweet thisAlerts:
@SheldonJun 14.2006 — oh What is the names of the table row?

can you shoe me that layout of you mysql table?
Copy linkTweet thisAlerts:
@franknuauthorJun 14.2006 — the name of the table is Categories and the column is categories

SELECT *

FROM Categories LIMIT 0 , 30
Copy linkTweet thisAlerts:
@SheldonJun 14.2006 — ok then try this exact script and call it [url=http://www.mass-ad.com/freedisplay2.php?Categories=automotive]wiht this[/url]

[code=php]
<?php

$host = "localhost";
$username = "localhost";
$password = "abc123";
$database = "contacts";

$db = mysql_connect($host, $username, $password);
mysql_select_db($database);

if(isset($_GET['Categories']))
{
$Categories = addslashes($_GET['Categories']);
}else{
echo("No Categories found.");
exit;
}


$query = "SELECT * Categories WHERE Categories = '".$Categories."' ";
$result = mysql_query($query) or die (mysql_error());
$num_result = mysql_num_rows($result);


if($num_result <= 0)
{
echo("No Results found.");
exit;
}

echo("<p>Number of business found: ".$num_result."</p>";
while($row = mysql_fetch_array($result))
{

echo "<p><strong>BusinessName ";
echo ($row["Slogan"]);
echo "</strong><br>Address ";
echo (stripslashes($row["Business_Address"]));
echo "<br>ISBN: ";
echo (stripslashes($row["Make"]));
echo "<br>State: ";
echo (stripslashes($row["type"]));
echo "<br>Price: ";
echo (stripslashes($row["Tel"]));
echo "</p>";
}

?>
[/code]
×

Success!

Help @franknu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...