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
Expand|Select|Wrap|Line Numbers
- <?php
- $username="forpet";
- $password="dogrnnr2";
- $database="forpet";
- mysql_connect(localhost,$username,$password);
- @mysql_select_db($database) or die("Unable to select database");
- ?>
- <form method="POST" action="search2.php">
- <?php $sql = mysql_query("SELECT type FROM listings ORDER BY type ASC"); while ($row = mysql_fetch_array($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>
Expand|Select|Wrap|Line Numbers
- <?php
- $username="forpet";
- $password="dogrnnr2";
- $database="forpet";
- mysql_connect(localhost,$username,$password);
- @mysql_select_db($database) or die("Unable to select database");
- ?>
- <form method="POST" action="results.php">
- <?php
- $sql = mysql_query("SELECT * FROM listings WHERE type LIKE '$type'");
- while ($row = mysql_fetch_array($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("SELECT * FROM listings WHERE type LIKE '$type'");
- while ($row = mysql_fetch_array($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>
Expand|Select|Wrap|Line Numbers
- <?php
- $username="forpet";
- $password="dogrnnr2";
- $database="forpet";
- mysql_connect(localhost,$username,$password);
- @mysql_select_db($database) or die("Unable to select database");
- $query="SELECT * FROM listings WHERE area LIKE '$area' AND type LIKE '$type'";
- $result=mysql_query($query);
- $num=mysql_numrows($result);
- mysql_close();
- echo "<b><center>Results for $type in $area</center></b><br><br>";
- $i=0;
- while ($i < $num) {
- $type=mysql_result($result,$i,"type");
- $area=mysql_result($result,$i,"area");
- $name=mysql_result($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++;
- }
- ?>
-Stephanie
For php, CODE tags should be like this.
[code=php]
Not Just
[code]
Anyway thanks for using [code] Tags.