Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 855 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Alternating Table Columns via while() Loop

Thread title: Alternating Table Columns via while() Loop
Closed Thread    
    Thread tools Search this thread Display Modes  
03-30-2005, 03:12 AM
#1
Jon Mooring is offline Jon Mooring
Status: I'm new around here
Join date: Jan 2005
Location:
Expertise:
Software:
 
Posts: 14
iTrader: 0 / 0%
 

Jon Mooring is on a distinguished road

  Old  Alternating Table Columns via while() Loop

I am writing a script that displays items for sale in each category. Obviously, the items are gathered from the database and put into a variable via a while() loop. What I want to do is put them into two seperate variables. One for each of two table columns. I want every other item to alternate. Like:

item 1 -> column 1
item 2 -> column 2
item 3 -> column 1
etc, etc ,etc...

How would I go about doing this? Thanks in advance.

03-30-2005, 04:07 AM
#2
Travis is offline Travis
Status: Member
Join date: Jul 2004
Location:
Expertise:
Software:
 
Posts: 445
iTrader: 0 / 0%
 

Travis is on a distinguished road

  Old

Assuming this is done with php and with a database something like this(please note I have not done php for a while and this is off the top of my head):

PHP Code:
<?

/*
 * Some sought of database connection/query up here
 * or perhaps an array or something to store the items
 */

$column1 "<td>";
$column2 "<td>";

$i 1;
while(
$row mysql_fetch_array()) {
   if(
$i 1) {
      
$column1 .= $row[item] . "<br>";
      
$i 2;
   } else {
      
$column2 .= $row[item] . "<br>";
      
$i 1;
   }
}

$column1 .= "</td>";
$column2 .= "</td>";

/*
 * Then you would have a table down here some where
 * and you would print out the 2 column variables
 */
?>

03-30-2005, 12:51 PM
#3
Travis is offline Travis
Status: Member
Join date: Jul 2004
Location:
Expertise:
Software:
 
Posts: 445
iTrader: 0 / 0%
 

Travis is on a distinguished road

  Old

Just noticed the forums got split into different ones. This doesn't belong in HTML and CSS. It belongs in the programming forum.

03-31-2005, 02:56 AM
#4
Jon Mooring is offline Jon Mooring
Status: I'm new around here
Join date: Jan 2005
Location:
Expertise:
Software:
 
Posts: 14
iTrader: 0 / 0%
 

Jon Mooring is on a distinguished road

  Old

Thanks Travis, I'll implement this immediately Should work, looks right.

03-31-2005, 01:02 PM
#5
DateinaDash is offline DateinaDash
Status: The BidMaster
Join date: Nov 2004
Location: England
Expertise:
Software:
 
Posts: 10,821
iTrader: 0 / 0%
 

DateinaDash is on a distinguished road

  Old

Thread has been moved to correct forum now Trav

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed