Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 9th, 2003, 09:53 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
Quick Boolean Question

if your seraching a DB using a HTML form is it possible to seach the DB with some fields left empty?

ie.

name = david
dob =
city = glasgow

php Code:
Original - php Code
  1. $thisquery = SELECT * from data WHERE name = '$name' AND dob = '$dob' AND city = '$city; 


so that would search the table named data for a result where name = 'david', dob='' and city = 'glasgow'.

would this work properly?

reason i ask is because i ran this query in myphpadmin and although the query was performed succesfuly it didnt produce any results....

cheers!

david*

Reply With Quote
  #2  
Old September 9th, 2003, 11:17 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Quick Boolean Question

No...you'll need to build your query dynamically based on what form fields are set....

Here is a mini example:

php Code:
Original - php Code
  1. $where = array();
  2. if(isset($_POST['field1']) {
  3.     $where[] = "db1 = '$_POST[field1]'";
  4. }
  5. if(isset($_POST['field2']) {
  6.     $where[] = "db2 = '$_POST[field2]'";
  7. }
  8. if(isset($_POST['field3']) {
  9.     $where[] = "db3 = '$_POST[field3]'";
  10. }
  11. $where = implode(" AND ", $where);
  12. $sql = "SELECT * FROM table WHERE $where";


Hope that helps...

Reply With Quote
  #3  
Old September 9th, 2003, 01:16 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: Quick Boolean Question

very cool matey, cheers.

heard but never used the implode function. going to check it out right now.

this is resolved,

david*

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Quick Boolean Question


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