table cells and rows array, looping

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paulng
Forum Commoner
Posts: 28
Joined: Mon Jul 11, 2005 9:31 am

table cells and rows array, looping

Post by paulng »

Hi!

I m retrieve data from a database using the following sql statement:

Code: Select all

sql_query = "SELECT * FROM $table WHERE StartDate <= '$currdate' AND EndDate >= '$currdate' ORDER BY DisplayOrder ASC LIMIT 4";
,

Now, I was wandering if anyone could help in writing array that display the result output from the above sql in the follow way:

I have 2 tables, first table has 2 colums and 1 row, the second table has 1row and 1colum.

I've attempted to write an array that loop the first part of the result and dispays it in the first collum of the first table, then loop to get the second result and display it in the second colum on the first table.

and finally the remaining result in the next table all in ASC order.

If anyone could help I will very much appreciate your help as I seemsnot to get anywhere with my result.

here is my table:

Code: Select all

<table width="600" border="1" cellpading="2" cellspacing="2"><tr><td>cell 1</td><td>cell2</td></tr></table>
   <br>
   <table width="600" border="1" cellpading="2" cellspacing="2"><tr><td>cell 3</td></tr></table>

Many Thanks!

paulng :cry:
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I can't really understand what your getting at.

What fields are in your MySQL table?
Which cell (1, 2 or 3) do you want each field to go in?

Just explain a bit clearer please :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So do you want $result[0] in cell 1, $result[1] in cell 2, $result[2] in cell 3, so on? Also, why would you use a one row one column table, why not use <div> tags to separate each line and stylize them?
paulng
Forum Commoner
Posts: 28
Joined: Mon Jul 11, 2005 9:31 am

Post by paulng »

Everah, Jayshield

Thank you both for your replies, as Everah suggests that is what I would like to achieve...Everah in terms of styling I dont understand what you mean if you could please elaborate regarding the <div> to organinse my table.

Paulng.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

First off, for the two column table loop, you are going to need to use a counter of some sort so you know if you are on an even index or odd. You are also going to need to set up a delimiter to see if you are closing just a cell or a cell AND a row. You will also need to check the last value in the array and it's odd/even index value to see if you need to add an empty cell at the end of your table before closing it.

As far as the one column table, all that this does is act as a pretty set of <br /> tags. Why not use <div> tags with some CSS styling to get the same result?
Post Reply