Ok, I worked with these queries and got them to work (mostly) but I have one issue left.
The count query gives me an accurate count now, but the query for the search fields gives me a low number of records. So when I put them together within my pagination code, I end up with a pagination (count) of 1575 records, but the search produces only 258 records, so my pagination 'runs out' of data before it should.
IE both queries are not ending up with the same number of rows.
In this search, I used EmailAddress ='yahoo' and state ='Illinois'.
And I think what is happening is it is only giving me the records where those 2 fields match and including all records where the other fields are blank, instead of all records that match just the EmailAddress and State and ignoring the other fields.
Here is the COUNT query:
$query_count = "SELECT COUNT(*) as totalCount FROM max8_copy WHERE";
if($EmailAddress != NULL || $EmailAddress != "") {
$query_count .= " EmailAddress LIKE '%$EmailAddress%' AND";
}
if($FirstName != NULL || $FirstName != "") {
$query_count .= " FirstName LIKE '%$FirstName%' AND";
}
if($LastName != NULL || $LastName != "") {
$query_count .= " LastName LIKE '%$LastName%' AND";
}
if($City != NULL || $City != "") {
$query_count .= " City LIKE '%$City%' AND";
}
if($State != NULL || $State != "") {
$query_count .= " State LIKE '%$State%'";
}
if($Zip != NULL || $Zip != "") {
$query_count .= " Zip LIKE '%$Zip%'";
}
And here is the search query:
$query = "SELECT * FROM max8_copy WHERE";
if($EmailAddress != NULL || $EmailAddress != ""
|| $FirstName != NULL || $FirstName != ""
|| $LastName != NULL || $LastName != ""
|| $City != NULL || $City != ""
|| $State != NULL || $State != ""
|| $Zip != NULL || $Zip != "") {
$query .= " EmailAddress LIKE '%$EmailAddress%'
AND FirstName LIKE '%$FirstName%'
AND LastName LIKE '%$LastName%'
AND City LIKE '%$City%'
AND State LIKE '%$State%'
AND Zip LIKE '%$Zip%'
ORDER BY EmailAddress ASC
LIMIT $limitvalue, $limit";
}
Thanks for the help,
Don