Jump to content

Archived

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

RabPHP

Counting As You Loop

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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
[code]
$count = 0;
while() {
  // do something
  $count++
}
[/code]

Share this post


Link to post
Share on other sites
Perfect! Thank you much, I didn't realize it was that easy.

This was the last piece of a major project. Thanks!

Rab

Share this post


Link to post
Share on other sites

×

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.