Impreza04
04-17-2006, 10:31 AM
The following code while working, causes alot of queries..
$cars = $db->query("SELECT * FROM " . TABLE_PREFIX . "lapsdb_carsets WHERE car_id = {$categorys['carid']} ORDER BY car_id ASC ");
$car_name = $db->fetch_array($cars);
$users = $db->query("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = {$categorys['submitter']} ORDER BY userid ASC ");
$user_name = $db->fetch_array($users);
$kleur = ($e % 2) ? $class='alt2' : $class='alt1';
$lapsbycat[lap_id] = $categorys['lap_id'];
$lapsbycat[carid] = $car_name['car_name'];
$lapsbycat[trackid] = $categorys['trackid'];
$lapsbycat[lap_time] = $categorys['lap_time'];
$lapsbycat[submitter] = $user_name['username'];
$lapsbycat[comments] = $categorys['comments'];
Specifically the $cars and $users queries..
These two match up ID's with a respective name, and displays that instead of the IDs.
However this means that every record creates two queries, 20 records per page means its running 49 Queries per page.
Anyone know how I could potentially reduce the amount?
Help is greatly appreciated
$cars = $db->query("SELECT * FROM " . TABLE_PREFIX . "lapsdb_carsets WHERE car_id = {$categorys['carid']} ORDER BY car_id ASC ");
$car_name = $db->fetch_array($cars);
$users = $db->query("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = {$categorys['submitter']} ORDER BY userid ASC ");
$user_name = $db->fetch_array($users);
$kleur = ($e % 2) ? $class='alt2' : $class='alt1';
$lapsbycat[lap_id] = $categorys['lap_id'];
$lapsbycat[carid] = $car_name['car_name'];
$lapsbycat[trackid] = $categorys['trackid'];
$lapsbycat[lap_time] = $categorys['lap_time'];
$lapsbycat[submitter] = $user_name['username'];
$lapsbycat[comments] = $categorys['comments'];
Specifically the $cars and $users queries..
These two match up ID's with a respective name, and displays that instead of the IDs.
However this means that every record creates two queries, 20 records per page means its running 49 Queries per page.
Anyone know how I could potentially reduce the amount?
Help is greatly appreciated