RE: [PHP] putting a list of data into 3 columns?

From: Date: Mon, 09 Apr 2001 08:09:01 +0000
Subject: RE: [PHP] putting a list of data into 3 columns?
Groups: php.general 
Request: Send a blank email to php-general+get-47742@lists.php.net to get a copy of this message
Here is a basic (untested) example. $link = mysql_connect("localhost", "username", "password"); mysql_select_db("database", $link); $result = mysql_query("SELECT product_name FROM products", $link); $num_rows = mysql_num_rows($result); // read in data while ($row = mysql_fetch_array ($result)) { $products[] = $row["product_name"]; } // display data $num_display_rows = ceil($num_rows / 3) $indx = 0; while ($indx < $num_display_rows) { echo "{$products[$indx]}, {$products[$indx+$num_rows]}, {$products[$indx+$num_rows*2]}"; $indx++; } -Stewart -----Original Message----- From: DRN [mailto:donaldrnoble@NOSPAM.yahoo.com] Sent: 07 April 2001 19:55 To: php-general@lists.php.net Subject: [PHP] putting a list of data into 3 columns? Hi, I would like to display a list of products from a MySQL database in 3 columns. as shown below: Product A Product D Product G Product B Product E Product H Product C Product F The problem I have is I don't know how many products there will be, so I can't just print out the first 3, start new column, print out next three, start new column, print out rest, end table. I presume I will have to count the number of results, then use this to wok out how many have to go in the first column etc. As I have only recently started using PHP / MySQL I am not sure how this should be done, has anybody done this (or something similar) so that I could look at the relevant code. Many thanks for your help, Donald -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#47742) next »