Re: putting a list of data into 3 columns?

From: Date: Sat, 07 Apr 2001 19:17:23 +0000
Subject: Re: putting a list of data into 3 columns?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47579@lists.php.net to get a copy of this message
Assuming your items are in an array $items =array() //assume a bunch of items in this array For($i = 0; $i< (count($items)/3); $i +=1){ printf("%s\t%s\t%s",$items[$i],$items[$i+3],$items[$i+6]); } Should print 3 columns of tab separated text. Note: typed this quickly, untested, but the theory is sound. Might have to twiddle the $i<(count... Section. If you have 8 itesm, as shown and you divide by 3 you get 2.xx So, the the loop will print out: $items[0] $items[3] $items[6] $items[1] $items[4] $items[7] $items[2] $items[5] $items[8} // because $items[8] doesn't exist, it won't print. // if it spits out an error there, put a @in front of printf to turn off error reporting. On 4/7/01 11:58 AM, "Jack Dempsey" <dempsejn@georgetown.edu> wrote: > You don't need to count...in your loop you can do something like this: > if($current_pos%3==0){ //then you're at a multiple of three > //code to start new column here > } > > -jack > > -----Original Message----- > From: DRN [mailto:donaldrnoble@NOSPAM.yahoo.com] > Sent: Saturday, April 07, 2001 2:55 PM > 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 > > > >

« previous php.general (#47579) next »