How's my code? A loop question
Posted: Tue Dec 12, 2006 1:56 pm
Hi, I've been using this huge code for years to create list pages... with alternating cell backgrounds for multiple entries. I know i'm not calling the data properly in this sample, but the meat is really in the script anyways.
What are your thoughts, is there something lighter than this to count entries, and display them in a list?
What are your thoughts, is there something lighter than this to count entries, and display them in a list?
Code: Select all
$sql = "SELECT COUNT(*) FROM table'";
$numrecord = mysql_query($sql);
$numrecords = mysql_fetch_array($numrecord);
$intRecsPerPage=100;
if($_POST["intpage"]=="")
{
$intpage=1;
}
$sql = "SELECT * FROM table";
$result = mysql_query($sql) or die (mysql_error());
$totalpages = intval(($numrecords[0])/$intRecsPerPage);
if(intval($numrecords[0]/$intRecsPerPage) != ($numrecords[0]/$intRecsPerPage))
{
$totalpages = $totalpages + 1;
}
for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
{
if($x/2 != intval($x/2))
{
$bgcolor = "#ffffff";
}
else
{
$bgcolor = "#F7F7F7";
}
if($x >= $numrecords[0])
{
break;
}
$issueresults = mysql_fetch_array($result);
//BEGIN LOOP
<tr><td bgcolor=$bgcolor>sample</td></tr>
//END LOOP
}