if(empty($Search)) { results_left = $max_results; // For each of the five priority levels. for($z=1; $z<6; $z++) { if(is_numeric($CategoryPassedBack)) { category_query = sprintf("AND Category=%s", quote_smart($CategoryPassedBack)); } else { category_query = ""; } // Find up to $results_left machinery in the table with the priority level $z. $query = sprintf("SELECT * FROM Machinery WHERE Priority=$z %s ORDER BY Make ASC LIMIT %s, %s", category_query, quote_smart($from), quote_smart($results_left)); // Count the number of machines within the table with a priority level $z. $num = mysql_num_rows(mysql_query($query)); $results_left -= $num; echo "Priority " . $z . ". Rows: " . $num . "<br />"; display_machinery($query1); } } else { // other stuffs }