Hello,
I have my code working and it displays 10 results per page and has pagination.
Now, what I would like is to have the table cells switching in color.
table cell 1: white
table cell 2: grey
table cell 3: white
and so on...
If anyone could help me out or can point me to a topic that has handled this subject before (could't find one myself) it would be greatly appreciated!
Current code:
<?
$HTTP_GET_VARS["cat"];
if ($cat == "") ($section = "12");
else $section = $cat;
$DBHost = "****";$DBUser = "****";$DBPass = "****";$DBName = "****";
$DBConn = mysql_connect($DBHost,$DBUser,$DBPass) or die("Unable to connect to database");
$DBSele = mysql_select_db("$DBName") or die("Unable to select database $DBName");
$DBQuery = "SELECT id FROM ringtones WHERE sectionid = $section";
/* Set current, prev and next page */
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 10;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
/* Query the db for total results. You need to edit the sql to fit your needs */
$result = mysql_query("$DBQuery") or die (mysql_error());
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$pagination = '';
/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '<a href="index.php?page='.$prev.'">Previous</a> ';
}
/* Loop through the total pages */
$HTTP_GET_VARS["cat"];
if ($cat == "") ($cat = "12");
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= '<b>'.$i.'</b>';
}
else
{
$pagination .= ' <a href="header.php?page='.$i.'&cat='.$cat.'">'.$i.'</a>';
}
}
/* Print NEXT link if there is one */
if($page < $total_pages)
{
$pagination .= ' <a href="header.php?page='.$next.'&cat='.$cat.'">Next</a>';
}
echo '<table width="100%">';
$result=mysql_query("SELECT * FROM ringtones WHERE sectionid = $section LIMIT $from, $max_results ");
while ($i = mysql_fetch_array($result))
{
/* This is where you print your current results to the page */
echo '<tr><td bgcolor="#FFFFFF">'. $i["ringtoneid"] . ' - ' . $i["artist"] . ' - ' . $i["song"] . '</td></tr>';
}
echo '</table><br />';
echo $pagination;
?>