Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Click Here
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old August 26th, 2002, 07:22 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Select WHERE column=* ?

Hey there. Glad to find a site like this. I just started playing with php and mySQL tonight for the first time, and I've come across a snag.

Here's the setup:
I've created a database, and I want the user to select the criteria to search on. They can pick "A","B", or "C" from the pulldown menu, and I have that pulled into the "Select" statement in the page it calls. Works like a champ.

However, I'd also like for them to be able to choose a "Show all" for that category, where "A", "B", and "C" would show up. How can I do this?

Working example page: http://www.cccmemphis.org/catsearch.php

You can select "DSH" or "DMH", but selecting "Show all breeds" returns nothing. I currently have the value of "Show all breeds" set to null.

The php code I have now:


The search page

php Code:
Original - php Code
  1.  
  2. <form method="post" action="catsearchpage.php">
  3. Gender:<select name="catgender" size="1">
  4. <option value=Female>Female</select><br>
  5. Breed:<select name="catbreed" size="1">
  6. <option value="">Show all breeds!
  7. <option value="Domestic Short Hair">DSH
  8. <option value="Domestic Medium Hair">DMH
  9. </option>
  10. </select><br>
  11. Fixed?:<select name="catfixed" size="1">
  12. <option value="Yes">Yes</select><br>
  13. <input type="Submit" name="submit" value="Search">
  14. </form>


and the catsearchpage.php that the form calls:

php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. $dbh=mysql_connect ("localhost", "cccmemph_jimlord", "fsoop") or die ('I cannot connect to the database.');
  5. mysql_select_db ("cccmemph_Testing");
  6.  
  7. $result = @mysql_query("SELECT * FROM adoptme
  8. WHERE gender = '$catgender'
  9. AND breed = '$catbreed'
  10. AND fixed = '$catfixed'
  11. AND status = 'Adoptable'");
  12. if (!$result) {
  13.   echo("<p>Error performing query: " . mysql_error() . "</p>");
  14.   exit();
  15. }
  16. echo("<table>");
  17. while ( $row = mysql_fetch_array($result) ) {
  18.   // process the row...
  19. echo("<tr><td valign=top>Name: " . $row["name"] . "</br>");
  20. echo("Gender: " . $row["gender"] . "</br>");
  21. echo("Coat: " . $row["coat"] . "</br>");
  22. echo("Breed: " . $row["breed"] . "</br>");
  23. echo("Disposition: " . $row["disposition"] . "</br>");
  24. echo("Birthdate: " . $row["birthdate"] . "</br>");
  25. echo("Status: " . $row["status"] . "</br>");
  26. echo("Fixed?: " . $row["fixed"] . "</br>");
  27. echo("Description: " . $row["description"] . "</td><td valign=top>");
  28. echo("<img width=250 src=" . $row["photo"] . "></td><tr>");
  29. }
  30. echo("</table>");
  31.  
  32. ?>
  33.  


Looks like I'm going to like this stuff, and next I'll be building the admin for someone else to do the updating of content. I run a site that someone else has designed using ASP, so I'm a bit familiar with the concepts here, but not coding. Any help is appreciated.

Reply With Quote
  #2  
Old August 26th, 2002, 05:33 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Select WHERE column=* ?

nevermind. Figured it out. I made the SELECT part a string and just tested to see if the choice was "All" before adding that part of the statement to the sting.

php Code:
Original - php Code
  1.  
  2. $lookup = "SELECT * FROM adoptme WHERE status = 'Adoptable'";
  3.  
  4. if ($catgender != "All")
  5. {
  6. $lookup = $lookup . "AND gender = '$catgender' ";
  7. }
  8. if ($catbreed != "All")
  9. {
  10. $lookup = $lookup . "AND breed = '$catbreed' ";
  11. }
  12. echo ("$lookup <p>");
  13.  
  14. $result = @mysql_query($lookup);
  15. if (!$result) {
  16.   echo("<p>Error performing query: " . mysql_error() . "</p>");
  17.   exit();
  18. }
  19. if (mysql_num_rows($result) > 0)
  20. {
  21.  

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Select WHERE column=* ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway