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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.