Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-16-2006, 01:40 AM Columns
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
I'm having a total brain freeze and can't figure this out

Basically, pretend you've got an array with 15 items. You want to print item in a table that has 5 columns and three rows. Buuutt, you want the list to go down, not across (see image). And each row has to be printed at once, so you can't just print a column at a time.

Something like... $key = $last_key + $rows... or something...

I've done it before, but my brain has totally gone blank.
Attached Images
File Type: gif Untitled-1.gif (18.4 KB, 9 views)
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-16-2006, 02:47 AM Re: Columns
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
It's 2am, so I didn't think of the simple way and instead jumped right into the hard way

Just created an array of $row[rownum][colnum] and then echoed it out after it was built.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 07-16-2006, 06:40 PM Re: Columns
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I don't know if this could be declared as an "easy" approach, but I came up with the following.

You have to forgive the math formula (I was always bad w/ math)!

PHP Code:
<?php
  
  $items 
= Array();
  
  
$items[1] = 'A';
  
$items[2] = 'B';
  
$items[3] = 'C';
  
$items[4] = 'D';
  
$items[5] = 'E';
  
$items[6] = 'F';
  
$items[7] = 'G';
  
$items[8] = 'H';
  
$items[9] = 'I';
  
$items[10] = 'J';
  
$items[11] = 'K';
  
$items[12] = 'L';
  
$items[13] = 'M';
  
$items[14] = 'N';
  
$items[15] = 'O';
  
  
$rows 3;
  
$cols 5;
    
  echo 
'<table cellpadding="8" border="1">';
  for(
$r 0$r $rows$r++) {
    
    echo 
'<tr>';
    for(
$i 1$i <= count($items) / $rows$i++) {
      
      echo 
'<td>' $items[( ($i $rows) + ($r $rows 1) )] . '</td>';
    }
    
    echo 
'</tr>';
  }
  
  echo 
'</table>';
  
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Columns
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40797 seconds with 13 queries