2 dimensional array
Hi PHP Geeks,
Please show me how to populate data in the same field into
multiple rows and columns.
Say i have xxx rows in the database. I want to populate them into
2 dimensional array but can't get it to work.
I was able to print out the rows and columns as below, but i have problem to populate data from the database. Please help.
Thank you very much.
<?
//data from the database
$linkid = "xxxx";
$sql = mssql_query("select image from myimagedata", $linkid);
while($data = mssql_fetch_array($sql))
{
$all_image[] = $data["image"];
}
$total_rows = mssql_num_rows($sql);
$num_rows_to_display = $total_rows/5;
$num_rows_to_display = round($num_rows_to_display);
$num_cols = 5; //I want 5 columns per row
//start to print out the row
print "<table>";
for($r=0; $r<$num_rows_to_display; $r++)
{
print "<tr>";
//start to print the columns
for($c=0; $c<$num_cols; $c++)
{
print "<td>";
print "i don't know how to populate the data in here";
print "</td>";
}
print "</tr>";
}
print "</table>";
?>
So that is my problem. Please help.
Thank you so much.
|