473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Having similar records only display once with a mysql database using PHP

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
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $username="forpet";
  3. $password="dogrnnr2";
  4. $database="forpet";
  5.  
  6. mysql_connect(localhost,$username,$password);
  7. @mysql_select_db($database) or die("Unable to select database");
  8.  
  9. ?>
  10.  
  11. <form method="POST" action="search2.php">
  12.  
  13. <?php $sql = mysql_query("SELECT type FROM listings ORDER BY type ASC"); while ($row = mysql_fetch_array($sql)) { ?>
  14.  
  15. Type of Listing:
  16. <select name="type">
  17. <option name="<?php echo $row['type']; ?>" id="<?php echo $row['type']; ?>"> <?php echo $row['type']; ?> </option> <?php } ?>
  18. </select>
  19. <input type="submit" value="Continue Search"><br><br>
  20. </form>
SEARCH2.PHP
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $username="forpet";
  3. $password="dogrnnr2";
  4. $database="forpet";
  5.  
  6. mysql_connect(localhost,$username,$password);
  7. @mysql_select_db($database) or die("Unable to select database");
  8.  
  9. ?>
  10.  
  11. <form method="POST" action="results.php">
  12.  
  13. <?php
  14.  
  15. $sql = mysql_query("SELECT * FROM listings WHERE type LIKE '$type'");
  16. while ($row = mysql_fetch_array($sql)) { ?>
  17.  
  18. Type of Listing:
  19. <select name="type">
  20. <option name="<?php echo $type; ?>" id="<?php echo $type; ?>"> <?php echo $type; ?> </option> <?php } ?>
  21. </select>
  22. <br>
  23. <br>
  24.  
  25. <?php
  26.  
  27. $sql = mysql_query("SELECT * FROM listings WHERE type LIKE '$type'");
  28. while ($row = mysql_fetch_array($sql)) { ?>
  29.  
  30. Area/Location:
  31. <select name="area">
  32. <option name="<?php echo $row['area']; ?>" id="<?php echo $row['area']; ?>"> <?php echo $row['area']; ?> </option> <?php } ?>
  33. </select>
  34. <input name="" type="submit" value="Display Listings">
  35.  
  36. </form>
RESULTS.PHP
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $username="forpet";
  3. $password="dogrnnr2";
  4. $database="forpet";
  5.  
  6. mysql_connect(localhost,$username,$password);
  7. @mysql_select_db($database) or die("Unable to select database");
  8.  
  9. $query="SELECT * FROM listings WHERE area LIKE '$area' AND type LIKE '$type'";
  10. $result=mysql_query($query);
  11.  
  12. $num=mysql_numrows($result);
  13.  
  14. mysql_close();
  15.  
  16. echo "<b><center>Results for $type in $area</center></b><br><br>";
  17.  
  18. $i=0;
  19. while ($i < $num) {
  20.  
  21. $type=mysql_result($result,$i,"type");
  22. $area=mysql_result($result,$i,"area");
  23. $name=mysql_result($result,$i,"name");
  24. $content=mysql_result($result,$i,"content");
  25. $address=mysql_result($result,$i,"address");
  26.  
  27. echo "<b>$name</b><br>$content<br>$address<br><hr><br>";
  28.  
  29. $i++;
  30.  
  31. }
  32.  
  33. ?>
THANK YOU SO MUCH!
-Stephanie


For php, CODE tags should be like this.
[code=php]
Not Just
[code]

Anyway thanks for using [code] Tags.
Jul 6 '07 #1
3 2864
okay i figured this out - all i needed was a DISTINCT clause. :)
Jul 7 '07 #2
ak1dnar
1,584 Expert 1GB
okay i figured this out - all i needed was a DISTINCT clause. :)
Hi Stephanie,
Glad to hear that you've figured it out your self.Welcome to TSDN anytime.
Jul 8 '07 #3
banning
42
okay i figured this out - all i needed was a DISTINCT clause. :)

LOL that makes me so mad, i hate it when its a stupid easy answer to stuff like this haha... i had the exact same problem and i was just thinking about how retarded it was that the solution has to be simple.

its a good thing i ran across your question on here i hate having to word my problems out for people on message boards n stuff lol

thanks :P
Aug 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want...
3
by: Mike | last post by:
Using MS Access XP standard install (no Jet or MDAC updates applied yet) as front end, MySQL 4.0 as backend and MySQL ODBC connector version 3.51. When pasting multiple records into the database...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
2
by: underground | last post by:
Hi, everyone I've been trying to figure out a way for a user to update there information. I'm using sections to identify the specific user..Here is the form <? include("include/session.php");...
8
by: menmysql | last post by:
i am not bale to solve this problem since two weeks i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and...
6
by: fpcreator2000 | last post by:
Hello everyone. I'm having problems with a page I've created that is used to insert data into a database. It uploads two files into two distinct folder, and it takes the filenames and inserts...
3
by: mikec87 | last post by:
I am very new with PHP...started doing this a few days ago to help someone and I need some help please. I have a webpage that is not displaying the records I want it to. The sql is correct, and I...
7
by: iahamed via WebmasterKB.com | last post by:
Hi all, I need to display records Horizontally, I do not know for some reason this code gives me an error, uses an access db. Microsoft VBScript compilation (0x800A040E) 'loop' without 'do'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.