<table align="left" style="width: 764px">
	<tr>
	<td>
	<?php
	$con =mysql_connect("localhost","root","");
	mysql_select_db("administration",$con);

	$list=mysql_query("SELECT * FROM cycles");
	echo "<table border=1>";
	echo "<tr>" ;
	echo "<td align=center style='color:red'>CID</td>";
	echo "<td align=center style='color:green'>Brand</td>";
	echo "<td align=center style='color:red'>Type</td>";
	echo "<td align=center style='color:green'>Style</td>";
	echo "<td align=center style='color:red'>Model</td>";
	echo "<td align=center style='color:green'>Gear No</td>";
	echo "<td align=center style='color:red'>Frame</td>";
	echo "<td align=center style='color:green'>Group Set</td>";
	echo "<td align=center style='color:red'>Price</td>";
	echo "<td align=center style='color:green'>Release Date</td>";
	echo "</tr>";
			
	$bg = '#eeeeee'; // Set the background color.
	while($row=mysql_fetch_array($list))
	{
		$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
		echo "<tr>" ;
		echo "<td align=center>".$row['cycleID'] ."</td>";
		echo "<td align=center>".$row['brand']."</td>";
		echo "<td align=center>".$row['type']."</td>";
		echo "<td align=center>".$row['style']."</td>";
		echo "<td align=center>".$row['model'] ."</td>";
		echo "<td align=center>".$row['gearNo']."</td>";
		echo "<td align=center>".$row['frame']."</td>";
		echo "<td align=center>".$row['groupSet']."</td>";
		echo "<td align=center>".$row['price']."</td>";
		echo "<td align=center>".$row['releaseDate']."</td>";
		echo "</tr>";
	}
	echo "</table>";
	?>
	</td>
	</tr>
</table>

The code from line 23 - 26 is not functioning. Please help.

Recommended Answers

All 7 Replies

Hi, is the database throwing an exception? Does the code reach the closing table tag on line 40? Have you tried a record count to see if your row variable contains rows? try echoing the row count - otherwise the code looks fine.

first of all ... where do you use $bg ? i don't see something like
echo "<td bgcolor='".$bg."'> .. if your rows are all white (or #eeeeee) this might be the problem.

first of all ... where do you use $bg ? i don't see something like
echo "<td bgcolor='".$bg."'> .. if your rows are all white (or #eeeeee) this might be the problem.

I think silviuks, is right, you not using $bg as background color (you just set its value).

I want to alternate the bg colours, row by row, any suggestion.

<?php
@ $rpp; //Records Per Page
@ $cps; //Current Page Starting row number
@ $lps; //Last Page Starting row number
@ $a; //will be used to print the starting row number that is shown in the page
@ $b; //will be used to print the ending row number that is shown in the page


$q="Select SQL_CALC_FOUND_ROWS * from tablename";
$rs=mysql_query($q) or die(mysql_error());
$nr = mysql_num_rows($rs); //Number of rows found with LIMIT in actiong r

$q0="Select FOUND_ROWS()";
$rs0=mysql_query($q0) or die(mysql_error());
$row0=mysql_fetch_array($rs0);
$nr0 = $row0["FOUND_ROWS()"];
$i=$nr0;
while ($line=mysql_fetch_array($rs))
{
if($i %2 == 0)
{
echo "<tr>";
echo "<td>";
echo "<table bgcolor='#fefefe' width='73%' align='center' border='0'>";
echo "<tr><td width='25%'></td></tr>";
echo "</table>";
echo "</td>";
echo "</tr>";


}
else if($i %2 == 1)
{
echo "<tr>";
echo "<td>";
echo "<table bgcolor='#e5e1e1' width='73%' border='0' align='center'>";
echo "<tr><td width='55%'></td></tr>";
echo "</table>";
echo "</td>";
echo "</tr>";

}
$i--;
}
}

hope this works

echo "<tr bgcolor=$bg>"; instead of echo "<tr>";

Thanks guys, it solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.