stormx Posted February 12, 2009 Share Posted February 12, 2009 Let's get started, I want to be able to put a style on my PHP style but have no knowledge of what to do when it comes to every second <tr> If you can't understand me, what I want to do is for every first <tr> it will display <tr class="first"> and for every second <tr> I want it to display <tr class="second"> Here is my code so far: <?php $sql1 = mysql_query("SELECT * FROM `history` WHERE `user` = '$user1'") or die("Cannot select usage at this time."); $sql1_rows = mysql_num_rows($sql1); if($sql1_rows == "0") { echo 'No Usage Found'; } else { echo '<table width="100%" border="0" cellpadding="5" cellspacing="1" class="shared"> <tbody> <tr class="titles"> <th>Date</th> <th>Disk Usage</th> <th>Disk Limit</th> <th>Bandwidth Usage</th> <th>Bandwidth Limit</th> </tr>'; while($invoices = mysql_fetch_array($sql1)) { echo '<tr class="first"> <td align="left">'.$invoices['date'].'</td> <td align="left">'.$invoices['disk_usage'].'</td> <td align="left">'.$invoices['disk_limit'].'</td> <td align="left">'.$invoices['bandwidth_usage'].'</td> <td align="left">'.$invoices['bandwidth_limit'].'</td> </tr>'; } echo '</table>'; } ?> So every second time this is echo'd I need it to be something like: <tr class="second"> <td align="left">'.$invoices['date'].'</td> <td align="left">'.$invoices['disk_usage'].'</td> <td align="left">'.$invoices['disk_limit'].'</td> <td align="left">'.$invoices['bandwidth_usage'].'</td> <td align="left">'.$invoices['bandwidth_limit'].'</td> </tr> Thanksyou Link to comment https://forums.phpfreaks.com/topic/144850-solved-php-table-with-css-style-help/ Share on other sites More sharing options...
drisate Posted February 12, 2009 Share Posted February 12, 2009 // Define first befor loop $row = "1"; //in your loop if($row==1){echo "class=\"first\"";$row="2";}else{echo "class=\"second\"";$row="1";} Link to comment https://forums.phpfreaks.com/topic/144850-solved-php-table-with-css-style-help/#findComment-760092 Share on other sites More sharing options...
stormx Posted February 12, 2009 Author Share Posted February 12, 2009 // Define first befor loop $row = "1"; //in your loop if($row==1){echo "class=\"first\"";$row="2";}else{echo "class=\"second\"";$row="1";} I understand it a bit but I don't understand how to use it in the script, please explan a bit more. Link to comment https://forums.phpfreaks.com/topic/144850-solved-php-table-with-css-style-help/#findComment-760093 Share on other sites More sharing options...
drisate Posted February 12, 2009 Share Posted February 12, 2009 Like this <?php $sql1 = mysql_query("SELECT * FROM `history` WHERE `user` = '$user1'") or die("Cannot select usage at this time."); $sql1_rows = mysql_num_rows($sql1); if($sql1_rows == "0") { echo 'No Usage Found'; } else { echo '<table width="100%" border="0" cellpadding="5" cellspacing="1" class="shared"> <tbody> <tr class="titles"> <th>Date</th> <th>Disk Usage</th> <th>Disk Limit</th> <th>Bandwidth Usage</th> <th>Bandwidth Limit</th> </tr>'; // Define first befor loop $row = "1"; while($invoices = mysql_fetch_array($sql1)) { echo '<tr '; //in your loop if($row==1){echo "class=\"first\"";$row="2";}else{echo "class=\"second\"";$row="1";} echo '> <td align="left">'.$invoices['date'].'</td> <td align="left">'.$invoices['disk_usage'].'</td> <td align="left">'.$invoices['disk_limit'].'</td> <td align="left">'.$invoices['bandwidth_usage'].'</td> <td align="left">'.$invoices['bandwidth_limit'].'</td> </tr>'; } echo '</table>'; } ?> Link to comment https://forums.phpfreaks.com/topic/144850-solved-php-table-with-css-style-help/#findComment-760096 Share on other sites More sharing options...
stormx Posted February 12, 2009 Author Share Posted February 12, 2009 Like this <?php $sql1 = mysql_query("SELECT * FROM `history` WHERE `user` = '$user1'") or die("Cannot select usage at this time."); $sql1_rows = mysql_num_rows($sql1); if($sql1_rows == "0") { echo 'No Usage Found'; } else { echo '<table width="100%" border="0" cellpadding="5" cellspacing="1" class="shared"> <tbody> <tr class="titles"> <th>Date</th> <th>Disk Usage</th> <th>Disk Limit</th> <th>Bandwidth Usage</th> <th>Bandwidth Limit</th> </tr>'; // Define first befor loop $row = "1"; while($invoices = mysql_fetch_array($sql1)) { echo '<tr '; //in your loop if($row==1){echo "class=\"first\"";$row="2";}else{echo "class=\"second\"";$row="1";} echo '> <td align="left">'.$invoices['date'].'</td> <td align="left">'.$invoices['disk_usage'].'</td> <td align="left">'.$invoices['disk_limit'].'</td> <td align="left">'.$invoices['bandwidth_usage'].'</td> <td align="left">'.$invoices['bandwidth_limit'].'</td> </tr>'; } echo '</table>'; } ?> Thankyou so much, works like a treat. Link to comment https://forums.phpfreaks.com/topic/144850-solved-php-table-with-css-style-help/#findComment-760099 Share on other sites More sharing options...
drisate Posted February 12, 2009 Share Posted February 12, 2009 Np bro have fun :-) Link to comment https://forums.phpfreaks.com/topic/144850-solved-php-table-with-css-style-help/#findComment-760103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.