Ok...
There is a search page...
It has about five text boxes for the user to enter the data they are searching for.
At the bottom, there is two radio boxes, for OR and for AND, these radio boxes are named anyall.
One value is set to "or" one is set to "and".
Everything works great until I want to find more then one thing and use the boxes.
The OR, or the AND whichever is clicked, is appearing at the end of each statement in the where clause, even though the next field would be empty... so it won't find anything!!!
So I am getting this as the query:
SELEFT * FROM thisTable WHERE letter='A' OR name='marc' OR
I have the code set up like this:
$SELECT = "SELECT *";
$FROM = "FROM thisTable";
$WHERE = "WHERE ";
if(!isset($anyall) && $anyall == "") {
$anyall = "";
}
if(isset($letter) && $letter != "") {
$letter = strtoupper(trim($letter));
$WHERE .= " letter = '$letter' $anyall";
}
if(isset($name) && $name != "") {
$letter = strtoupper(trim($name));
$WHERE .= " name = '$name' $anyall";
}
if(isset($home) && $home != "") {
$letter = strtoupper(trim($home));
$WHERE .= " home = '$home' $anyall";
}
$query = "$SELECT $FROM $WHERE";
}
Can someone help me figure out a good way to make it so that if the next search field is empty the $anyall will stop at the end of the last variable and not continue appearing in the statment?