472,794 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 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 2813
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
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.