PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old September 4th, 2008, 03:10 AM
gopa gopa is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 20 gopa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 41 sec
Reputation Power: 0
Send a message via AIM to gopa
php5 - How to dsplay data in tabular form?

I am fetching data from the table(MySQL). I want to display the data of only one field(40 records) in tabular form i.e. in 4 columns & 10 rows. That means it should display like this:
product1 in:Row1,Column1
product2 in:Row2,Column1
product3 in:Row3,Column1
.
.
.

product10 in:Row10,Column1

product11 in:Row1,Column2
product12 in:Row2,Column2
....like that

for ex it should be:
a e i m
b f j n
c g k o
d h l p

Please reply. Thanks in advance

Reply With Quote
Old September 4th, 2008, 11:43 AM
IAmALlama IAmALlama is offline
Me
Click here for more information
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,290 IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 11 h 27 m 17 sec
Reputation Power: 10
put the data into 4 arrays, one for each column and then compile it into your html code.
PHP Code:
<?php
//get the results from the db.
$r mysql_query("SELECT `column` FROM `table` LIMIT 40");
//number of columns
$cols 4;
//number of rows from result.
$count mysql_num_rows($r);
//init some vars.
$i 0;
$cols = array();
//loop through the results.
while($row mysql_fetch_assoc($r)){
    
//get the column number. floor(loop count divided by ceil(maximum number of rows))
    //should get us a number from 0 to 3.
    
$col floor($i/ceil($count/$cols));
    
//add the row to a multi-dimensional array using the column number from above.
    
$cols[$col][] = $row['column'];
    
//add 1 to our loop count.
    
$i++;
}

//displaying
echo "<table>";
for(
$i=0;$i<count($cols[0]);$i++){
    echo 
"<tr>";
    foreach(
$cols as $k=>$v){
        echo 
"<td id='R".($i+1)."C".($k+1)."'>{$v[$i]}</td>";
    }
    echo 
"</tr>";
}

echo 
"</table>";
?>

something like that should work. I haven't tested it, but it should be close enough to get it working.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php5 - How to dsplay data in tabular form?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap