Greaser9780 Posted February 21, 2007 Share Posted February 21, 2007 This is my code: while($r=mysql_fetch_array($sql1)) { $rank=1; $list = "<table>"; $list .="<td width='61'>$rank </td>; $list .="<td width='150' align='left'>".$r['name']."</TD>"; $list .="<td width='150' align='left'>".$r['1pick']."</td>"; $list .="<td width='50' align='left'>".$r['1pos']."</td>"; $list .="</table>"; echo $list; } How can I incorporate $rank++ so that my rank continues to 2 on the 2nd listing? Link to comment https://forums.phpfreaks.com/topic/39508-solved-how-to-get-to-work-in-a-list-table/ Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 Put $rank=1 outside the loop, and inside it do $rank++; Link to comment https://forums.phpfreaks.com/topic/39508-solved-how-to-get-to-work-in-a-list-table/#findComment-190610 Share on other sites More sharing options...
marcus Posted February 21, 2007 Share Posted February 21, 2007 $rank=1; while($r=mysql_fetch_array($sql1)){ $list = "<table>"; $list .="<td width='61'>$rank </td>; $list .="<td width='150' align='left'>".$r['name']."</TD>"; $list .="<td width='150' align='left'>".$r['1pick']."</td>"; $list .="<td width='50' align='left'>".$r['1pos']."</td>"; $list .="</table>"; $rank++; echo $list; } Link to comment https://forums.phpfreaks.com/topic/39508-solved-how-to-get-to-work-in-a-list-table/#findComment-190611 Share on other sites More sharing options...
Greaser9780 Posted February 21, 2007 Author Share Posted February 21, 2007 Thanks for the input. Why does the $rank++ go outside of the $list? It works that way but why? Link to comment https://forums.phpfreaks.com/topic/39508-solved-how-to-get-to-work-in-a-list-table/#findComment-190615 Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 mgall's code has a missing ", as obvious by the colors. $list is a string of html. $rank++ is php incrementing a variable. That's why they don't go together.... Link to comment https://forums.phpfreaks.com/topic/39508-solved-how-to-get-to-work-in-a-list-table/#findComment-190618 Share on other sites More sharing options...
Greaser9780 Posted February 21, 2007 Author Share Posted February 21, 2007 Happy to hear the answer. I tried about 10 differentways to incorporate it into the table or td but to no avail.As usual ty for the expert advice. Link to comment https://forums.phpfreaks.com/topic/39508-solved-how-to-get-to-work-in-a-list-table/#findComment-190622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.