cinq
06-11-2004, 04:41 PM
I have a table for data items, cars stored in the database.
I want to have a page which lists all the cars stored in the database ( thumbnails of the cars ).
How am I to go about outputting them in a single page, in rows of 5 thumbnails, for a total of 4 rows ( ie. 20 per page ) and then have page navigation ( ie. each page has 20 thumbnails ).
How do I go about limiting the sql queries in this case ?
The hack I am working on is based on magnus's vgarage.
The current code now stands at :
if ($_REQUEST['do'] == 'list')
{
globalize($_REQUEST, array('pagenumber' => INT, 'perpage' => INT));
$perpage = intval($perpage);
if ($perpage == 0 or $perpage > 200)
{
$perpage = 20;
}
if (intval($pagenumber) == 0)
{
$pagenumber = 1;
}
$limitlower = ($pagenumber - 1) * $perpage + 1;
$limitupper = ($pagenumber) * $perpage;
$counter = 0;
$carcount = $DB_site->query_first("
SELECT COUNT(*) AS cars FROM " . TABLE_PREFIX . "vbgarage_users
");
$numberpages = $carcount['cars'] / $perpage;
$numberpages = ceil($numberpages);
if (!isset($pagenumber) or ($pagenumber < 1) or ($pagenumber > $numberpages))
$pagenumber = 1;
$pos = ($pagenumber - 1) * $perpage;
$result_list = $DB_site->query("SELECT * FROM vbgarage_users ORDER BY lastactivity DESC LIMIT $pos,$perpage ");
$counter = 0;
while ($list = $DB_site->fetch_Array($result_list) AND $counter++ < $perpage)
{
$list['lastactivity'] = vbdate($vboptions['dateformat'],$list['lastactivity'],true);
$user = fetch_userinfo($list[userid]);
$cid = $list['carid'];
$result_list2 = $DB_site->query("SELECT * FROM vbgarage_comments WHERE carid=$cid");
$numcomments = mysql_num_rows($result_list2);
$result_list1 = $DB_site->query("SELECT * FROM vbgarage_images WHERE carid=$cid ORDER BY imageid DESC LIMIT 1");
while ($list1 = $DB_site->fetch_Array($result_list1))
{
eval('$latestbits .= "' . fetch_template('vbgarage_latestbits') . '";');
}
}
$pagenav = construct_page_nav($carcount[cars],"vbgarage.php?$session[sessionurl]do=$_REQUEST[do]&perpage=$perpage");
eval('print_output("' . fetch_template('vbgarage_listgarage') . '");');
}
I want to have a page which lists all the cars stored in the database ( thumbnails of the cars ).
How am I to go about outputting them in a single page, in rows of 5 thumbnails, for a total of 4 rows ( ie. 20 per page ) and then have page navigation ( ie. each page has 20 thumbnails ).
How do I go about limiting the sql queries in this case ?
The hack I am working on is based on magnus's vgarage.
The current code now stands at :
if ($_REQUEST['do'] == 'list')
{
globalize($_REQUEST, array('pagenumber' => INT, 'perpage' => INT));
$perpage = intval($perpage);
if ($perpage == 0 or $perpage > 200)
{
$perpage = 20;
}
if (intval($pagenumber) == 0)
{
$pagenumber = 1;
}
$limitlower = ($pagenumber - 1) * $perpage + 1;
$limitupper = ($pagenumber) * $perpage;
$counter = 0;
$carcount = $DB_site->query_first("
SELECT COUNT(*) AS cars FROM " . TABLE_PREFIX . "vbgarage_users
");
$numberpages = $carcount['cars'] / $perpage;
$numberpages = ceil($numberpages);
if (!isset($pagenumber) or ($pagenumber < 1) or ($pagenumber > $numberpages))
$pagenumber = 1;
$pos = ($pagenumber - 1) * $perpage;
$result_list = $DB_site->query("SELECT * FROM vbgarage_users ORDER BY lastactivity DESC LIMIT $pos,$perpage ");
$counter = 0;
while ($list = $DB_site->fetch_Array($result_list) AND $counter++ < $perpage)
{
$list['lastactivity'] = vbdate($vboptions['dateformat'],$list['lastactivity'],true);
$user = fetch_userinfo($list[userid]);
$cid = $list['carid'];
$result_list2 = $DB_site->query("SELECT * FROM vbgarage_comments WHERE carid=$cid");
$numcomments = mysql_num_rows($result_list2);
$result_list1 = $DB_site->query("SELECT * FROM vbgarage_images WHERE carid=$cid ORDER BY imageid DESC LIMIT 1");
while ($list1 = $DB_site->fetch_Array($result_list1))
{
eval('$latestbits .= "' . fetch_template('vbgarage_latestbits') . '";');
}
}
$pagenav = construct_page_nav($carcount[cars],"vbgarage.php?$session[sessionurl]do=$_REQUEST[do]&perpage=$perpage");
eval('print_output("' . fetch_template('vbgarage_listgarage') . '");');
}