Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

while($row=mysql_fetch_array($result)): Peek into next iteration?

Status
Not open for further replies.

jpo245

Programmer
Jan 16, 2005
45
US
I have a page that displays results from a query in a grouped manner. In my instance, the query returns a list of members in some clubs.

I have the results "Grouped" according to the club, so it a single Table Header for a club, and then the rows below that table header are its members.

A new table header will be created when a new club is encountered.

How the logic works, is that I store the ClubID for each iteration, and whenever i go to a new record, it will compare the new ClubID with the old one to determine if it should create a new table header or not.

Creating table headers is easy.

However, i am at the point where i am within a specific iteration of while($row=mysql_fetch_array($result)), is there a quick way to peek into the results of the NEXT iteration, without actually leaving the one I am at?

like for example, $row[1][CURRENT+1] would peek into $row[1] of the next iteration.

I searched the docs but can't seem to find help...

Thanks!

while($row=mysql_fetch_array($result))

 
Maybe you can store it into array

Code:
   $MyArray = array();
   while($row=mysql_fetch_array($result)) {
      $ClubID = $row['ClubID'];
      if (isset($MyArray[$ClubID]) { 
        //append data
        $MyArray[$ClubID] = $MyArray[$ClubID] . $yourdata;
      }
      else {
        $MyArray[$ClubID] = $yourdata;
      }
   }
  print_r($MyArray);

gry online
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top