Table colours fail when extra row added
Posted on
16th Feb 2014 07:03 pm by
admin
Hey Gurus,
I got a weird problem with formating the colour of a table made in php. Everything works fine when i use 5 rows each row has an alturnative colour, but when i add the 6th row the colour fails and every row is the same colour which is the first colour (green). I used the same technique on every row so i dont understand how it fails with an extra row. Heres the code:
Line number On/Off | Expand/Contract $result = mysql_query("SELECT * FROM fulldata WHERE approved = '0'") or die(mysql_error() ); $i=1; $row = mysql_fetch_array($result); $line = mysql_fetch_assoc($result); // headers of the tableecho "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"; echo "<tr><td align='left' width='40%'><b>Description</b></th><td align='center' width='30%'><b>Proof</b></th><td align='center' width='10%'><b>Workers Needed</b></th><td align='center' width='10%'><b>Price</b></th><td align='center' width='10%'><b>Accept</b></th><td align='center' width='10%'><b>Deney</b></th></tr>";// ITERATE OVER THE RESULTS SET while ($line = mysql_fetch_assoc($result)) {// GET EASY-TO-READ LOCAL VARIABLES foreach ($line as $key => $val) { $$key = htmlentities($val); }// CREATE THE ROW OF DATA $color = ($i % 2) ? "#3F6" : "#3CF"; echo "<tr>"; echo "<td style='background-color:$color' align='center'>$descript</td>n"; $i++; echo "<td style='background-color:$color' align='center'>$proof</td>n"; $i++; echo "<td style='background-color:$color' align='center'>$amountworkers</td>n"; $i++; echo "<td style='background-color:$color' align='center'>$perperson</td>n"; $i++; echo "<td style='background-color:$color' align='center'>Accept</td>n"; $i++; echo "<td style='background-color:$color' align='center'>Deney</td>n"; $i++; } // END WHILE ITERATOR echo "</table>n"; // END IF/ELSE ?>
that last row Quote: echo "<td style='background-color:$color' align='center'>Deney</td>n";
$i++; when added ruins all the colours. when taken out the table works fine
Your Answer:
Login to answer
284
13
Other forums
help with email script...
hey
I need help with my mail script
when the form on http://www.mcgdesignstudio.com/c
Retrieving innerHTML with cURL?
Hey all (sorry I know I'm a leecher, but I soon won't be. This is my first PHP project, but not my l
Reading Most Recent CSV File in Directory
I thought I had wrapped this project up, but found out that the program I use to FTP a csv file to m
Why does my crawler script suddenly end with no error?
Hi.
I have written a web crawler script. It will visit a large number of URL's with cURL.
Saving PHP output as a file
I wondered if anyone knows how to save the rendered output of a PHP script as a file?
I have
PDO returns erroneous columns from within pdt
Hi All,
This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns a
PHP login form help (Done Most of It)
Hi i am having a problem, when i try logging in it is always saying "Invalid Login" im not
Array disappearing in foreach loop
Okay, I have this problem where an array will become undefined in a foreach loop.
Here is the
How to ask a regex question?
Hi, I thought I'd share some of my insight after seeing too many bad questions that either get ignor
PHP not creating file.
Its supposed to create a .ini file in the /scriptfiles/users/ with the name they entered into the fi