Page 1 of 1
tabular query output
Posted: Thu Feb 15, 2007 6:21 am
by rubberjohn
hi,
ive been away from php for a while and as a result i am struggling with formatting the out put of a query into a nice and neat table.
the query can return multiple record sets. in each set is 6 records - title, image url, price 1, price 2, % difference in prices and finally a link.
I want each record set to be displayed in a column - ie
title
image url
price 1
price 2
% difference
link
This I can (still) do, but what I am having trouble with is displaying a line fo four of these across the screen. All i am managing to do is is to get them repeating down the screen instead of accross it.
amy help would be greatly appreciated
rj
Posted: Thu Feb 15, 2007 7:20 am
by Oren
Please post the related code you have and an example of how exactly you want the output to look like.
And please try to be more specific when describing your problem.
Posted: Thu Feb 15, 2007 8:25 am
by rubberjohn
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
sorry i thought i had been specific...
i do not want the output to be like this - repeating down the screen:
title
image url
price 1
price 2
% difference
link
title
image url
price 1
price 2
% difference
link
title
image url
price 1
price 2
% difference
link
etc
i want it to display across the screen like this - this is the best i could do to get it aligned
Code: Select all
title title title
image url image url image url
price 1 price 1 price 1
price 2 price 2 price 2
% difference % difference % difference
link link link
off the top of my head the code i am using is this...
Code: Select all
$output = '<table width="200" border="1" cellspacing="1" cellpadding="1">';
sql query here
while sql query !=0{
$output .= '
<tr>
<tr>
<td>title</td>
</tr>
<tr>
<td>image url</td>
</tr>
<tr>
<td>price 1</td>
</tr>
<tr>
<td>price 2</td>
</tr>
<tr>
<td>% difference</td>
</tr>
<tr>
<td>link</td>
</tr>';
}
$output .= '</table>'
i then echo $output.
The syntax may not be right but thats pretty much what it is - im not infront of my home pc at the minute.
Thanks
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Feb 15, 2007 8:30 am
by feyd
The output you wish requires caching the result set into PHP, processing it (to rotate the information) then using a variety of techniques to output the information.
The first two threads referenced from Useful Posts are applicable to your situation (particularly the second one, if memory serves.)
Posted: Thu Feb 15, 2007 8:49 am
by rubberjohn
cheers feyd i feared it would involve something like that - i just wanted to know if there was an easier way to do it.
so it would involve collecting all the titles, urls, price 1 etc together and outputing them individually but in a way that still groups the relevant related records together - ill check out those other posts
what about using a mutli-d array?
Posted: Thu Feb 15, 2007 9:17 am
by feyd
It will require a two-dimensional array.
Posted: Thu Feb 15, 2007 10:23 am
by Oren
Well, I suggest that instead of relaying on PHP to rotate it and all the other processes involved here, just use PHP to output something like the below and then use CSS to make it look like the elements of the outer list are at the same row.
Code: Select all
<ul>
<li>
<ul>
<li>title</li>
<li>img url</li>
<li>price1</li>
<li>price2</li>
<li>% diff</li>
<li>link</li>
</ul>
</li>
<li>
<ul>
<li>title</li>
<li>img url</li>
<li>price1</li>
<li>price2</li>
<li>% diff</li>
<li>link</li>
</ul>
</li>
.
.
.
<li>
<ul>
<li>title</li>
<li>img url</li>
<li>price1</li>
<li>price2</li>
<li>% diff</li>
<li>link</li>
</ul>
</li>
</ul>
Posted: Tue Feb 20, 2007 3:36 pm
by rubberjohn
cheers for that, i'll have a look at both methods and see which works out best.
thanks again
Posted: Wed Feb 21, 2007 4:45 pm
by rubberjohn
oren cheers for that - that method looks like it would work perfectly except that some of the images vary a little in height and some of the associated text spans two lines, therefore each list would be a different height and so would not line up when displayed inline across the screen.
So i chose to use the method suggested by feyd (
viewtopic.php?t=25105) as the rows will accomodate different content sizes and should line up.
im just having trouble adding additional rows above and below the image - i'll keep trying to sort it out but i'll probably be back tomorow
cheers again