Hey everyone!
I am completley new and I will start off by saying that I am not a programmer - figuring out this search took so long! I am debugging now and would appreciate any help :)
Anyways, I am creating a website where I have a database of pet listings in california. Each record lists the Type of Listing (eg. dog grooming or vet) the the Area it is in (so state, county etc.), a Name, Description, and Address.
I created a search so there are three pages. The first one has a pulldown menu where the user selects the type of listing they are looking for. Next, they select the area they wish to view, and then the records are all displayed that match those two critera (aka all dog grooming in san fran.)
Okay so here is my issue: There are about 45 Dog Grooming records, 240 Vets etc. And they ALL show up in the pulldown menus. Same with the areas.
is there a clause I can add to my code so once dog grooming is listed, it is no longer shown, yet still selects all of the records with dog grooming in it?
Please tell me if this does not make sense. And here is my code (please don't laugh, I am sure it is very messy! I am a designer :) not a coder ha. THANKS SO MUCH!
SEARCH.php
[CODE=php]<?php
$username="forp et";
$password="dogr nnr2";
$database="forp et";
mysql_connect(l ocalhost,$usern ame,$password);
@mysql_select_d b($database) or die("Unable to select database");
?>
<form method="POST" action="search2 .php">
<?php $sql = mysql_query("SE LECT type FROM listings ORDER BY type ASC"); while ($row = mysql_fetch_arr ay($sql)) { ?>
Type of Listing:
<select name="type">
<option name="<?php echo $row['type']; ?>" id="<?php echo $row['type']; ?>"> <?php echo $row['type']; ?> </option> <?php } ?>
</select>
<input type="submit" value="Continue Search"><br><br >
</form>[/CODE]
SEARCH2.PHP
[CODE=php]<?php
$username="forp et";
$password="dogr nnr2";
$database="forp et";
mysql_connect(l ocalhost,$usern ame,$password);
@mysql_select_d b($database) or die("Unable to select database");
?>
<form method="POST" action="results .php">
<?php
$sql = mysql_query("SE LECT * FROM listings WHERE type LIKE '$type'");
while ($row = mysql_fetch_arr ay($sql)) { ?>
Type of Listing:
<select name="type">
<option name="<?php echo $type; ?>" id="<?php echo $type; ?>"> <?php echo $type; ?> </option> <?php } ?>
</select>
<br>
<br>
<?php
$sql = mysql_query("SE LECT * FROM listings WHERE type LIKE '$type'");
while ($row = mysql_fetch_arr ay($sql)) { ?>
Area/Location:
<select name="area">
<option name="<?php echo $row['area']; ?>" id="<?php echo $row['area']; ?>"> <?php echo $row['area']; ?> </option> <?php } ?>
</select>
<input name="" type="submit" value="Display Listings">
</form>[/CODE]
RESULTS.PHP
[CODE=php]<?php
$username="forp et";
$password="dogr nnr2";
$database="forp et";
mysql_connect(l ocalhost,$usern ame,$password);
@mysql_select_d b($database) or die("Unable to select database");
$query="SELECT * FROM listings WHERE area LIKE '$area' AND type LIKE '$type'";
$result=mysql_q uery($query);
$num=mysql_numr ows($result);
mysql_close();
echo "<b><center>Res ults for $type in $area</center></b><br><br>";
$i=0;
while ($i < $num) {
$type=mysql_res ult($result,$i, "type");
$area=mysql_res ult($result,$i, "area");
$name=mysql_res ult($result,$i, "name");
$content=mysql_ result($result, $i,"content");
$address=mysql_ result($result, $i,"address");
echo "<b>$name</b><br>$content< br>$address<br> <hr><br>";
$i++;
}
?>[/CODE]
THANK YOU SO MUCH!
-Stephanie
I am completley new and I will start off by saying that I am not a programmer - figuring out this search took so long! I am debugging now and would appreciate any help :)
Anyways, I am creating a website where I have a database of pet listings in california. Each record lists the Type of Listing (eg. dog grooming or vet) the the Area it is in (so state, county etc.), a Name, Description, and Address.
I created a search so there are three pages. The first one has a pulldown menu where the user selects the type of listing they are looking for. Next, they select the area they wish to view, and then the records are all displayed that match those two critera (aka all dog grooming in san fran.)
Okay so here is my issue: There are about 45 Dog Grooming records, 240 Vets etc. And they ALL show up in the pulldown menus. Same with the areas.
is there a clause I can add to my code so once dog grooming is listed, it is no longer shown, yet still selects all of the records with dog grooming in it?
Please tell me if this does not make sense. And here is my code (please don't laugh, I am sure it is very messy! I am a designer :) not a coder ha. THANKS SO MUCH!
SEARCH.php
[CODE=php]<?php
$username="forp et";
$password="dogr nnr2";
$database="forp et";
mysql_connect(l ocalhost,$usern ame,$password);
@mysql_select_d b($database) or die("Unable to select database");
?>
<form method="POST" action="search2 .php">
<?php $sql = mysql_query("SE LECT type FROM listings ORDER BY type ASC"); while ($row = mysql_fetch_arr ay($sql)) { ?>
Type of Listing:
<select name="type">
<option name="<?php echo $row['type']; ?>" id="<?php echo $row['type']; ?>"> <?php echo $row['type']; ?> </option> <?php } ?>
</select>
<input type="submit" value="Continue Search"><br><br >
</form>[/CODE]
SEARCH2.PHP
[CODE=php]<?php
$username="forp et";
$password="dogr nnr2";
$database="forp et";
mysql_connect(l ocalhost,$usern ame,$password);
@mysql_select_d b($database) or die("Unable to select database");
?>
<form method="POST" action="results .php">
<?php
$sql = mysql_query("SE LECT * FROM listings WHERE type LIKE '$type'");
while ($row = mysql_fetch_arr ay($sql)) { ?>
Type of Listing:
<select name="type">
<option name="<?php echo $type; ?>" id="<?php echo $type; ?>"> <?php echo $type; ?> </option> <?php } ?>
</select>
<br>
<br>
<?php
$sql = mysql_query("SE LECT * FROM listings WHERE type LIKE '$type'");
while ($row = mysql_fetch_arr ay($sql)) { ?>
Area/Location:
<select name="area">
<option name="<?php echo $row['area']; ?>" id="<?php echo $row['area']; ?>"> <?php echo $row['area']; ?> </option> <?php } ?>
</select>
<input name="" type="submit" value="Display Listings">
</form>[/CODE]
RESULTS.PHP
[CODE=php]<?php
$username="forp et";
$password="dogr nnr2";
$database="forp et";
mysql_connect(l ocalhost,$usern ame,$password);
@mysql_select_d b($database) or die("Unable to select database");
$query="SELECT * FROM listings WHERE area LIKE '$area' AND type LIKE '$type'";
$result=mysql_q uery($query);
$num=mysql_numr ows($result);
mysql_close();
echo "<b><center>Res ults for $type in $area</center></b><br><br>";
$i=0;
while ($i < $num) {
$type=mysql_res ult($result,$i, "type");
$area=mysql_res ult($result,$i, "area");
$name=mysql_res ult($result,$i, "name");
$content=mysql_ result($result, $i,"content");
$address=mysql_ result($result, $i,"address");
echo "<b>$name</b><br>$content< br>$address<br> <hr><br>";
$i++;
}
?>[/CODE]
THANK YOU SO MUCH!
-Stephanie
Originally posted by Ajaxrand
Comment