954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

3 lines of code not working

<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.

lordx78
Junior Poster
180 posts since Oct 2007
Reputation Points: 10
Solved Threads: 2
 

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.

coffeepot!
Newbie Poster
11 posts since Feb 2008
Reputation Points: 10
Solved Threads: 2
 

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

silviuks
Junior Poster in Training
96 posts since Apr 2006
Reputation Points: 10
Solved Threads: 15
 

first of all ... where do you use $bg ? i don't see something like echo " .. 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).

rudevils
Junior Poster in Training
80 posts since Jan 2008
Reputation Points: 10
Solved Threads: 10
 

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

lordx78
Junior Poster
180 posts since Oct 2007
Reputation Points: 10
Solved Threads: 2
 

<?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 ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "";

} else if($i %2 == 1) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "";

} $i--; } }


hope this works

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 

echo ""; instead of echo "";

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Thanks guys, it solved.

lordx78
Junior Poster
180 posts since Oct 2007
Reputation Points: 10
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You