PHP: array - for every 4, "do this"?

Hitman
Soldato
Joined
25 Feb 2004
Posts
2,837
Hi,

Having a bit of a problem. I'm storing a bunch of data and retrieving it with mssql_fetch_array, and outputting it like so:


Code:
(code goes here to retrieve the details)

<table>

while( $row = mssql_fetch_array( $query ) )
{

	$type = $row["pm_type"];
	$id = $row["pm_id"];
	$name = $row["pm_name"];
	$img = $row["img"];
	$img_full = $row["img"] . "_full";
	$AP = SomeFunction( $type, $id );
	
	echo "<td>whatever here</td>";
}

</table>
What I'm trying to do is output 4 results per table, and then make another table if there's already 4 results in the previous table. Obviously with the above code I can't do that because the while puts it all inside one table.

Hope that's clear, and hope someone can help!

Cheers in advanced
 
Hi,

Managed to come up with this based on your code, feenster99:

Code:
$loop = 0;

while( $row = mssql_fetch_array( $query ) )
{
	if( $loop == 4 )
	{
		echo "</table>";
		$loop = 0;
		echo "<table>";
	}
	
	$loop++;

	echo "<td>whatever here</td>";
}
Yours didn't seem to work properly (excused though considering you were tired :p) but based on yours I've managed to cook that up and seems to work :)

Cheers
 
Back
Top Bottom