ozone1 Posted December 24, 2010 Share Posted December 24, 2010 Hi guys i need a little help to list data in different coloured rows i need to list 1st name in <td class="alt1"> 2nd name in <td class="alt2"> and so on currently it is listing only in <td class="alt1"> here is my code any help really appreciated <?php $result[0] = mysql_query("SELECT * FROM videos ORDER BY viewtoday DESC LIMIT 10"); for($i=0;$i<count($result);$i++) { echo ''; while($row=mysql_fetch_array($result[$i])) { $id = $row['id']; $cat = $row['cat']; $title = $row['title']; $numviews = $row['viewtoday']; $max_length = 25; $title = ( strlen($title) > $max_length ? substr($title,0,$max_length)."..." : $title ); echo '<table class="listOfShows listOfShowsFirst"><tr> <td class="alt1"> <a href="videos.php?id=' . $id . '">'. $title . '</a> </td> </tr>'; } } ?> </table></td></table>/php] Quote Link to comment https://forums.phpfreaks.com/topic/222597-php-alternate-row-help-please/ Share on other sites More sharing options...
.josh Posted December 24, 2010 Share Posted December 24, 2010 $class = ($c % 2 == 0) ? "alt1" : "alt2"; $c++; echo '<table class="listOfShows listOfShowsFirst"><tr> <td class="'.$class.'"> <a href="videos.php?id=' . $id . '">'. $title . '</a> </td> </tr>'; Quote Link to comment https://forums.phpfreaks.com/topic/222597-php-alternate-row-help-please/#findComment-1151190 Share on other sites More sharing options...
ozone1 Posted December 25, 2010 Author Share Posted December 25, 2010 thank a lot for the help it worked sorry to bother again how to i add number next to my results like below 1. name 1 2. name 2 3. 4. so on...... Quote Link to comment https://forums.phpfreaks.com/topic/222597-php-alternate-row-help-please/#findComment-1151418 Share on other sites More sharing options...
PHPTOM Posted December 25, 2010 Share Posted December 25, 2010 Your $i variable should give the number of the row thank a lot for the help it worked sorry to bother again how to i add number next to my results like below 1. name 1 2. name 2 3. 4. so on...... Quote Link to comment https://forums.phpfreaks.com/topic/222597-php-alternate-row-help-please/#findComment-1151421 Share on other sites More sharing options...
.josh Posted December 25, 2010 Share Posted December 25, 2010 though you'd probably want to use $i+1 because $i starts at 0 not 1. Quote Link to comment https://forums.phpfreaks.com/topic/222597-php-alternate-row-help-please/#findComment-1151428 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.