|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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...
|
|
#4
|
|||
|
|||
|
I need you to detail how your database table is structured and what data you want to output from that table.
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
Thanks a lot. I'll give it a try as soon as I can.
BTW, that site you gave, is that your code? |
|
#8
|
|||
|
|||
|
Quote:
|
|
#9
|
|||
|
|||
|
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]; } |
|
#10
|
|||
|
|||
|
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:
|
|
#11
|
|||
|
|||
|
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:
Last edited by mrl14 : July 23rd, 2003 at 03:36 PM. |
|
#12
|
|||
|
|||
|
Ah, simple fix:
PHP Code:
PHP Code:
|
|
#13
|
|||
|
|||
|
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 |
|
#14
|
|||
|
|||
|
|
|
#15
|
|||
|
|||
|
Thank you so much. Its working now
![]() |
|
#16
|
|||
|
|||
|
No problem at all... glad you got it going.
|
|
#17
|
|||
|