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 Quote Link to comment 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";} Quote Link to comment 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. Quote Link to comment 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>'; } ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
drisate Posted February 12, 2009 Share Posted February 12, 2009 Np bro have fun :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.