RabPHP Posted June 28, 2006 Share Posted June 28, 2006 Hey guys,Another question. I need to count the number of loops I have made in while statement as I go through them. Unfortunately I have no idea where to start, just that I want the variable $count to be what it translates to.The objective is to output the number of the loop as I loop through them. Here is the code...[code] $select_team = "SELECT *"; $from_team = " FROM mc_base"; $where_team = " WHERE mc_sponsor_id = '$myid'"; $sname_team = mysql_query($select_team . $from_team . $where_team, $dbcnx); while ($sname_view_list = mysql_fetch_array($sname_team)) { $member_fname = $sname_view_list["mc_fname"]; echo("<tr><td>$count</td>"); echo("<td>$member_fname</td></tr>"); echo("</table>}[/code]The output would look like an HTML table that would have...1 John Doe2 Jane Doe3 Matt Smith4 George BushEtcAny advice appreciated.Rab Quote Link to comment https://forums.phpfreaks.com/topic/13068-counting-as-you-loop/ Share on other sites More sharing options...
Michael4172 Posted June 28, 2006 Share Posted June 28, 2006 [code] $select_team = "SELECT *"; $from_team = " FROM mc_base"; $where_team = " WHERE mc_sponsor_id = '$myid'"; $sname_team = mysql_query($select_team . $from_team . $where_team, $dbcnx); $count = 0; while ($sname_view_list = mysql_fetch_array($sname_team)) { $count++; $member_fname = $sname_view_list["mc_fname"]; echo("<tr><td>$count</td>"); echo("<td>$member_fname</td></tr>"); echo("</table>}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13068-counting-as-you-loop/#findComment-50283 Share on other sites More sharing options...
trq Posted June 28, 2006 Share Posted June 28, 2006 [code]$count = 0;while() { // do something $count++}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13068-counting-as-you-loop/#findComment-50284 Share on other sites More sharing options...
RabPHP Posted June 28, 2006 Author Share Posted June 28, 2006 Perfect! Thank you much, I didn't realize it was that easy.This was the last piece of a major project. Thanks!Rab Quote Link to comment https://forums.phpfreaks.com/topic/13068-counting-as-you-loop/#findComment-50289 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.