By mysocom on
function show_list($uid) {
$res = db_query("SELECT * from {my_table} where uid = %d", $uid);
$res2 = db_query("SELECT * from {my_table} where uid = %d", $uid);
$out = (db_result($res) > 0) ? theme_list($res2) : "<p>No data.</p>";
return $out;
}
How can I get rid of second query ? (This code doesn't work with one query)
Comments
Change $res =
Change
$res = db_query("SELECT * from {my_table} where uid = %d", $uid);to$res = db_query("SELECT COUNT(some_field) from {my_table} where uid = %d", $uid);(replace some_field with a field in my_table will speed things up but not eliminate the first query.To use only one query have the theme function handle the case of no results.