Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 18th, 2005, 12:37 AM
Authorized User
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

Similar Threads
Thread Thread Starter Forum Replies Last Post
using 2 dimensional array Abraham EJB 0 July 17th, 2007 09:27 AM
two-dimensional array Lizane Java Basics 4 May 23rd, 2007 09:35 AM
Sorting 2 dimensional array rgalehouse Javascript How-To 2 December 2nd, 2006 10:46 AM
fill two-dimensional array tobian Excel VBA 0 February 21st, 2006 05:55 PM
2 dimensional array venterjo General .NET 2 January 23rd, 2005 09:04 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.