Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

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 Dev Shed Forums Sponsor:
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  
Old January 31st, 2002, 10:21 AM
gina1962 gina1962 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: Oklahoma
Posts: 4 gina1962 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to gina1962
Unhappy query in php

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";

Reply With Quote
  #2  
Old January 31st, 2002, 10:51 AM
binky's Avatar
binky binky is offline
Gerbil
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2001
Location: In a Rotastak
Posts: 1,763 binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 22 h 12 m 52 sec
Reputation Power: 18
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);

Reply With Quote
  #3  
Old January 31st, 2002, 12:47 PM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
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..."

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > query in php


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 2 hosted by Hostway