Re: BIG PROBLEM WITH SEARCH!!!!!!

From: Date: Sat, 20 Jan 2001 00:12:35 +0000
Subject: Re: BIG PROBLEM WITH SEARCH!!!!!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35760@lists.php.net to get a copy of this message
best way is this. if ($CID) $query[] = "CID = '$CID'"; if ($CUserName) $query[] = "CUserName = '$CUserName'"; if ($CAge) $query[] = "CAge = '$CAge'"; if ($CEducation) $query[] = "CEducation = '$CEducation'"; if (isset($query)) $query = "SELECT * FROM clients WHERE CID = '$CID' AND CUserName = '$CUserName' " . implode(' AND ', $query); else $query = "SELECT * FROM clients WHERE CID = '$CID' AND CUserName = '$CUserName' "; but this works too... $query = "SELECT * FROM clients WHERE CID = '$CID' AND CUserName = '$CUserName' "; if ($CAge) $query .= " AND CAge = '$CAge'"; if ($CEducation) $query .= " AND CEducation = '$CEducation'"; the latter only works if there is at LEAST one variable to be used. Is this what you meant? no? email me k. Chris Lee Mediawaveonline.com Mike Yuen <myuen@ucalgary.ca> wrote in message news:Pine.A41.4.10.10101191615470.84818-100000@acs5.acs.ucalgary.ca... > I'm developing a site that requires people to sign up. During this time, > we get their name, email, city, etc. There is also optional informational > like (age, education) that they don't have to fill in. > > Now, the problem we have is we allow people search through the database > using mostly the same criteria people filled in during their sign up. > However, if someone does not have a preference in Education or age, how do > we create a query that selects all the records. Currently, the SQL > statement has several "OR" clauses in between the optional fields > (ie: select * form clients where (CID='$CID' AND CUserName='$CUserName') > OR CAge='$CAge' OR CEducation='$CEducation'). > > You can see from the query that if someone has no preference, it will take > the value from the form and search just on that value - NOT everything. > > I'm stumped on how to solve this problem. Can anyone help me out? > > Thanks, > Mike > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#35760) next »