General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 22nd, 2003, 01:38 AM
mrl14 mrl14 is offline
1 Month Free Hosting!
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 15 mrl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Creating Dynamic Tables

I have a mysql table with 14 rows in it.

I want to create a table that is 3 cols long and has those 14 rows evently divided up inside the 3 cols. (note: the 14 rows could get bigger or smaller at any time)

How can I dynamically create this?

thanks

Reply With Quote
  #2  
Old July 22nd, 2003, 02:09 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
This link should give you all the code you need to work this problem out:

http://www.laidbak.net/phpsample/columnsplit/
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old July 22nd, 2003, 01:12 PM
mrl14 mrl14 is offline
1 Month Free Hosting!
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 15 mrl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I couldn't get that code to work. I also need to be able to link these words to their appropriate pages based on an ID # that is associated with each name...

Reply With Quote
  #4  
Old July 22nd, 2003, 05:35 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
I need you to detail how your database table is structured and what data you want to output from that table.

Reply With Quote
  #5  
Old July 22nd, 2003, 05:48 PM
mrl14 mrl14 is offline
1 Month Free Hosting!
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 15 mrl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Table called categories with 2 rows (cid, name).

ie.

1 - PHP
2 - HTML
3 - CSS

ETC.

I want a page to query this table and display the categories evenly thought 3 cols


Col1: --------- Col2: ----------Col3

PHP ------------ ASP------------BLAH
HTML -----------BLAH
CSS -------------BLAH


So lets say there are 7 categories it will see that 7/3 = 2.3 (round that up to 3)

then display that many rows in each col.

The categories will also link to the ID# associated with them - category.php?cid=$cid

Note : the category db will have more added to it as time goes on.

Let me know if you need further expanation.

Reply With Quote
  #6  
Old July 22nd, 2003, 06:32 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
All of this is in the code I gave you.

1. Create a multidimensional array from the db results maybe something like: $cat['id']['name'].

2. We know the number of columns you want: $numcol = 3;

3. Get the number of row results: $numitems = count($cat);

4. count the number of rows you will end up with
numrows = ceil($numitems / $numcol)

5. Start a loop for your table rows

6. Nest in another loop for your cells (columns), and write out the info in your array there between the <td></td> tags.

If you need a referece the sample code is still there.

Reply With Quote
  #7  
Old July 22nd, 2003, 08:56 PM
mrl14 mrl14 is offline
1 Month Free Hosting!
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 15 mrl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a lot. I'll give it a try as soon as I can.

BTW, that site you gave, is that your code?

Reply With Quote
  #8  
Old July 23rd, 2003, 01:12 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
Quote:
Thanks a lot. I'll give it a try as soon as I can. BTW, that site you gave, is that your code?
Yes, that is code I put together.

Reply With Quote
  #9  
Old July 23rd, 2003, 12:10 PM
mrl14 mrl14 is offline
1 Month Free Hosting!
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 15 mrl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
how do I create the 3D array when the values already come out in an array like this


while($row = @mysql_fetch_array($result)) {
$cid = $row[cid];
$name=$row[name];

}

Reply With Quote
  #10  
Old July 23rd, 2003, 03:00 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
My original suggestion was $cat['id']['name'], however you can do it like this:

$cat['id'] = 'name';
which would be the same as

$cat = Array('id'=>'name');

The code for that would be:

PHP Code:
while ($row = @mysql_fetch_array($result)) {
  
$cat[$row[cid]] = $row[name];


Reply With Quote
  #11  
Old July 23rd, 2003, 03:32 PM
mrl14 mrl14 is offline
1 Month Free Hosting!
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 15 mrl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok so far things are working.

Right now It is outputting the categories, however the first cell in the top left corner and last cell in the bottom right corner are blank (It should be the bottom 2 rows in the 3rd column that are blank).


(Edit: I added 2 more categories so there was an even 9...when this happened the 9th category did not appear until I added a 10th one. Most likely something to do with the first cell being blank)

So how would I get the $cid # to appear properly for each category name so that I can link it up.

Here is what I have so far.


PHP Code:
<?php

$result 
mysql_query("SELECT name, cid FROM category") or die(mysql_error()); 
        
$num_rows mysql_num_rows($result);
        while(
$row = @mysql_fetch_array($result)) { 
$cat[$row[cid]] = $row[name];  
}

$numcols =3;

// Number of Items 
$numitems =count($cat); 

// Number of Rows 
$numrows =ceil($numitems/$numcols); 
?>



<table border="2"> 

<th colspan="100%">Categories</th> 
<?php
        
for ( $row =1;$row <= $numrows ;$row ++) { 
            
// Initialize Cells 
            
$cell =0;
?> 
        <tr> 
<?php 
            
for ( $col =1;$col <= $numcols ;$col ++) { 
?> 
                <td> 
<?php 
        
if ( $col === 1) { 
        
$cell += $row ;
                print 
$cat [$cell -1]; 
    } else { 
         
$cell += $numrows ;
                print 
$cat [$cell -1]; 
        } 
?> 
                </td> 
<?php 
                 
}
?> 
        </tr> 
<?php 
         
}
?> 
</table>

Last edited by mrl14 : July 23rd, 2003 at 03:36 PM.

Reply With Quote
  #12  
Old July 23rd, 2003, 04:33 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
Ah, simple fix:
PHP Code:
for ( $row =1;$row <= $numrows ;$row ++) 
should be
PHP Code:
for ( $row =0;$row <= $numrows ;$row ++) 

Reply With Quote
  #13  
Old July 23rd, 2003, 05:03 PM
mrl14 mrl14 is offline
1 Month Free Hosting!
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 15 mrl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hmmm that makes 2 blanks at the top now...Also, how do I get the $cid to match up with the name so I can link them

Also one category is appearing twice and I don't see it twice in the db

Reply With Quote
  #14  
Old July 23rd, 2003, 06:03 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17

Reply With Quote
  #15  
Old July 23rd, 2003, 06:28 PM
mrl14 mrl14 is offline
1 Month Free Hosting!
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 15 mrl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you so much. Its working now

Reply With Quote
  #16  
Old July 23rd, 2003, 07:00 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
No problem at all... glad you got it going.

Reply With Quote
  #17  
Old December 20th, 2003, 10:18 AM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Atlanta GA
Posts: 73 zigote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 11 sec
Reputation Power: 17
Talking

I just wanted to says Thanks to laidbak, I was just looking for this, If I didn't search, I would have posted to the forum.

Thanks

Reply With Quote
  #18  
Old December 20th, 2003, 02:10 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
Again, I'm glad this was helpful to yet another person. I hope all goes well with your code.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Creating Dynamic Tables


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 - 2018, Jelsoft Enterprises Ltd.

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