brown2005 Posted January 15, 2007 Share Posted January 15, 2007 hi, what i want is to get a set of results from the mysql database and when usingwhile{}i want to change the colors of the rows... one red, one blue, one red, one blue.. thanks Link to comment https://forums.phpfreaks.com/topic/34220-changing-row-color/ Share on other sites More sharing options...
OOP Posted January 15, 2007 Share Posted January 15, 2007 Hi there,There are several ways for doing this...for example; you can do sothing like this:[code]$counter = 0;$result = 0;$color = ' ';while(....){ $result = $counter % 2; if($result == 0){ $color = 'red'; }elseif($result == 1){ $color = 'blue'; } $counter++;}[/code] Link to comment https://forums.phpfreaks.com/topic/34220-changing-row-color/#findComment-160983 Share on other sites More sharing options...
brown2005 Posted January 15, 2007 Author Share Posted January 15, 2007 $profile = "SELECT * FROM table A;"; $profile_query = mysql_query($profile) or die(mysql_error()); $current_price = ""; while($row = mysql_fetch_array($profile_query, MYSQL_ASSOC)) { if($row['month'] != $current_price) { echo"<tr> <th colspan='4'>".$row['month']."</th> </tr>"; $current_price = $row['month']; } echo"<tr> <td>".$row['position']."</td> <td>".$row['name']."</td> <td>".$row['hits']."</td> </tr>"; }Hi, sorry this is what i have currently.. wat i want is for the first row to be class='a' and second row to be class='2', and so on.how can i work this into the code above, please... Link to comment https://forums.phpfreaks.com/topic/34220-changing-row-color/#findComment-161061 Share on other sites More sharing options...
brown2005 Posted January 15, 2007 Author Share Posted January 15, 2007 echo"<tr> <td>".$row['position']."</td> <td>".$row['name']."</td> <td>".$row['hits']."</td> </tr>";this is the bit i want to change class on Link to comment https://forums.phpfreaks.com/topic/34220-changing-row-color/#findComment-161071 Share on other sites More sharing options...
brown2005 Posted January 15, 2007 Author Share Posted January 15, 2007 dont worry, ive sorted this now Link to comment https://forums.phpfreaks.com/topic/34220-changing-row-color/#findComment-161074 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.