Jump to content

Counting As You Loop


RabPHP

Recommended Posts

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 Doe
2 Jane Doe
3 Matt Smith
4 George Bush
Etc

Any advice appreciated.

Rab
Link to comment
https://forums.phpfreaks.com/topic/13068-counting-as-you-loop/
Share on other sites

[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]
Link to comment
https://forums.phpfreaks.com/topic/13068-counting-as-you-loop/#findComment-50283
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.