Hi peeps
This may have been asked before, but I couldn't find anything suitable with a search, so...
I want to display records from a database search, but vertically (in a table), ie
A E
B F
C G
D
Obviously the number of records is unknown, so there may be uneven rows (as above) - and I'm kind of stumped at the minute! I'm fairly new at PHP so can't really think of a way to run through the table displaying the records in such a way as I need. It only needs to be a 2-column layout, but having the ability to have more could be useful too.
Any help would be much appreciated!
Cheers.
Vertical Record Display
Moderator: General Moderators
-
Eric Praline
- Forum Commoner
- Posts: 32
- Joined: Wed Aug 29, 2007 8:37 am
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
how about something like:
*totally untested - that's in your court!
Code: Select all
for($i=0;$i<floor(count($records)/2);$i++){
echo "<tr>";
echo "<td>".$records[$i]."</td>"
echo "<td>".$records[$i+floor(count($records)/2)]."</td>"
echo "</tr>"
}-
Eric Praline
- Forum Commoner
- Posts: 32
- Joined: Wed Aug 29, 2007 8:37 am
Thanks feyd, the thread you mentioned had some useful info, in particular the code...
... was just the sort of thing I was looking for! [:D]
Now, it works - as in it splits results into 2 columns - but it doesn't display the actual data result, instead it just prints 'Array'. Now, I think it may be something to do with how the information is cached with the mysql_fetch_assoc line, so I tried mysql_fetch_array instead but that does the same. Unfortunately my brain has stopped working and I can't for the life of me remember what to do to fix it.
So, one last bit of help is required please to figure out how to display the actual query result...
But apart from that it's all been very helpful, cheers!
Code: Select all
// assume $result is the result set
// cache the data
$cache = array();
while($row = mysql_fetch_assoc($result))
{
$cache[] = $row;
}
$col2 = ceil(count($cache) / 2);
for($i = 0; $i < $col2; $i++)
{
echo '<tr><td>'.$cache[$i].'</td><td>'.(isset($cache[$i + $col2]) ? $cache[$i + $col2] : ' ').'</td>';
}Now, it works - as in it splits results into 2 columns - but it doesn't display the actual data result, instead it just prints 'Array'. Now, I think it may be something to do with how the information is cached with the mysql_fetch_assoc line, so I tried mysql_fetch_array instead but that does the same. Unfortunately my brain has stopped working and I can't for the life of me remember what to do to fix it.
So, one last bit of help is required please to figure out how to display the actual query result...
But apart from that it's all been very helpful, cheers!