Ok, so I have to resurrect this thread for a question...
But first: Thank you for posting the code!!!!! It made my life worth living (for now)...
Anyway, I used your code LordShryku with minor mods for my own evil purposes and I am having a problem with using ORDER BY
When I use ORDER BY, the search criteria sent from the search form no longer works and my results are just the whole table.
I'm guessing that it has something to do with WHERE 1=1, but what do I know? I'm just a noob trying to write some code for an Herbarium.
$query_species = 'SELECT * FROM plants WHERE 1 = 1 ORDER BY full_sci_name';
$query_species .= empty($_GET['family']) ? NULL : " AND family LIKE '".$_GET['family']."'";
$query_species .= empty($_GET['genus']) ? NULL : " AND genus LIKE '".$_GET['genus']."%'";
$query_species .= empty($_GET['species']) ? NULL : " AND species LIKE '".$_GET['species']."%'";
$query_species .= empty($_GET['lname']) ? NULL : " AND coll_lname LIKE '".$_GET['lname']."%'";
$query_species .= empty($_GET['county']) ? NULL : " AND county LIKE '".$_GET['county']."%'";
$query_species .= empty($_GET['locality']) ? NULL : " AND locality LIKE '%".$_GET['locality']."%'";
$query_limit_species = sprintf("%s LIMIT %d, %d", $query_species, $startRow_species, $maxRows_species);
$species = mysql_query($query_limit_species, $user_id) or die(mysql_error('Cannot connect to database.'));
Thanks in advance!