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 <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]