|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
I am doing a site that you should be able to search by sex, place and age. I can get it to search by all 3, but not if someone just does sex and place. Can anyone see what I'm doing wrong.
if ($search AND $sex_s AND $place_s AND $age_from AND $age_to) { $numresults = mysql_query("select * from user where sex like '$sex_s%' AND place like '$place_s%' AND (age between $age_from AND $age_to)"); $numrows=mysql_num_rows($numresults); $string = "select * from user where sex like '$sex_s%' AND place like '$place_s%' AND (age between $age_from AND $age_to) limit $offset,$limit"; $result=mysql_query($string); $URLNEXT = "&sex_s=$sex_s&age_from=$age_from&age_to=$age_to&place_s=$place_s&search=1&place=$place&sex=$sex"; } elseif ($search2 AND $sex_s AND $place_s) { $numresults = mysql_query("select * from user where place like '$place_s%' AND sex like '$sex_s%'"); $numrows=mysql_num_rows($numresults); $string = "select * from user where place like '$place_s%' AND sex like '$sex_s%' limit $offset,$limit"; $result=mysql_query($string); $URLNEXT = "&sex=$sex_s&place=$place_s&searh2=1&place=$place&sex=$sex"; |
|
#2
|
||||
|
||||
|
Sorry, it's getting too late in the day and all those $s are scary.
If it's coming from a form (which is most likely) then try: $sql = "select * from user where "; if (isset($sex)) { $sql .= "sex = $sex and "; } if (isset($place)) { $sql .= "place = $place and "; } if (isset($age)) { $sql .= "age = $age"; } $numresults = mysql_query($sql); |
|
#3
|
||||
|
||||
|
Please post this problem on PHP forum .you will get quick response from there.
__________________
SR - webshiju.com www.lizratechnologies.com "The fear of the LORD is the beginning of knowledge..." |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > query in php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|