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
array_combine() trouble w/csv file
I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I h
array_combine() trouble w/csv file
I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I h
Select Lists into MYSQL
Hello All, I am new to PHP @ 1 week. So borrowing code anywhere I can. I am making progress, but h
Array question
Does anyone know how to create a program that takes the $ amount for 8 different departments and gi
MySQL Primary key gap
Alright, so I have a table with 26 entries in it (id, filename, caption) for my image randomiser (ht
Session login issue
I'm wondering how to fix a problem I'm having with a session-based login system
Say I go to h
type check while uploading
Hi Everyone,
How can I check the exact type of a file while uploading on my site?
Here
Problem with Sending Mail by PHP
hello all,
I m new to php, can u plz provide me the code to send mail by php having CAPTC
What do you call the "token" thing?
You know how some sites have links that run on tokens? Tokens are links that only stay alive for a c
Get to know your fellow coder
I think it's time we got personal around here. There's a lot of code swapping and a few members kno