|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I display records horizontally?
Hi there,
I want to create a system which will display 4/5 fields from a record vertically using new rows for each field as normal. But then i want the records to display horizontally, with a limit of 4 records per row. Since there are kind of two row references (one for the rows containing the fields of the indivual record, and another to contain the completed records four at a time) it confusing me. I have found previous messages relating to displaying records horizontally, but non seem to include using multiple fields, and displaying these vertically, within the horizontal layout. Im presuming i have to use some kind of nestled loop but i cant figure out how to do it. Essentially i need to create a new row, then loop 1-4 through the records for the first field, then do a new row, loop 1-4 for field 2 and continue till ive got all four fields done. Then i guess i have to include some kind of modulus function to start new rows of rows (this is causing problems in itself) Do i need to use tables and rows rather than rows and tds because i have one more step than normal horizontal display? (i think) Any help would be greatly appreciated |
|
#2
|
||||
|
||||
|
I think your final conclusion is about right, though I'm having difficulty understanding precisely what it is you're trying to do. Based on my loose understanding, it sounds like nested tables might do the trick.
|
|
#3
|
|||
|
|||
|
ok, Heres some more details.
I have a table (members) with details such as name, image_url, email_address etc I want to display each record like this (pseudo code) <tr> <td>image url</td> </tr> <tr> name </tr> <tr> email_address </tr> This is so the info it displayed in one column. The problem is, that when the next record is parsed, it actually needs to insert a second <td> into each of the already existing rows. This needs to happen untill each of the rows above has 4 <td>'s in it (thats the number i want in each line) THEN...i need to start a new row with the records 5-8 in it, 3rd row 9-12 etc Does this make it any clearer? |
|
#4
|
||||
|
||||
|
Have you drawn it out on paper?
i find that helps sometimes when dealing with tables/columns/rows... Based on the example you've given, it sounds to me you want something like this: <table> <tr> <td>image1</td> <td>image2</td> <td>image3</td> </tr> <tr> <td>name1</td> <td>name2</td> <td>name3</td> </tr> <tr> <td>email_address1</td> <td>email_address2</td> <td>email_address3</td> </tr> </table> In which case, you were right about the modulus... Assuming every record contains three peices of data (like in this example), your entire table will be divisible by three... Giving each peice of data a sequential number may help (as a cell reference)... try the following in an html document: <table> <tr> <td>1. image1</td> <td>4. image2</td> <td>7. image3</td> </tr> <tr> <td>2. name1</td> <td>5. name2</td> <td>8. name3</td> </tr> <tr> <td>3. email_address1</td> <td>6. email_address2</td> <td>9. email_address3</td> </tr> </table> Look for the relation between the guidance numbers (1 through 9)... now remember hte use of modulus... Hopefully this helps... =) |
|
#5
|
|||
|
|||
|
yeah thats kinda the thing im trying to do.
I was following an example of how to do horizontal rows and managed to get it working with just one field, and i assumed i would be able to use nestled loops as shown below PHP Code:
This doesnt seem to work, it simply lists all the ids on one row - any ideas if theres anything fundimentally wrong here?Bearing in mind it works it you remove the inner loop |
|
#6
|
||||
|
||||
|
If you don't mind looping through the data twice, you could use mods to build arrays that position the data by index and then loop through the arrays to print stuff out in the right slots.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > How do I display records horizontally? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|