|
-
Jul 15th, 2007, 05:00 AM
#1
Thread Starter
Hyperactive Member
Help displaying data in four columns?
I have 28 rows of data, i know how to display the data.
The problem is that it lists the data in one column, I would like to display the 28 items within FOUR columns, equally.
In the future I'll have more than 28 rows...
data data data data
data data data data
data data data data
data data data data
Again, i would like the coulumns to contain the same amount of items, (unless it's an odd number of course)
Thanks!
Last edited by erbio; Jul 15th, 2007 at 02:48 PM.
-
Jul 15th, 2007, 03:57 PM
#2
Thread Starter
Hyperactive Member
Re: Help displaying data in four columns?
Code:
$query = "SELECT * FROM recent";
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
echo ceil($num_rows/4);
the echo displays 7
I just need to know how to put this data in FOUR columns, equally (unless odd of course)
Anyone?
-
Jul 15th, 2007, 06:29 PM
#3
Thread Starter
Hyperactive Member
Re: Help displaying data in four columns?
????.............................
-
Jul 16th, 2007, 12:09 AM
#4
Re: Help displaying data in four columns?
Are you displaying this using text or HTML or what?
Also, please don't keep bumping your thread, especially not at such short intervals.
-
Jul 16th, 2007, 12:22 AM
#5
Thread Starter
Hyperactive Member
Re: Help displaying data in four columns?
 Originally Posted by penagate
Are you displaying this using text or HTML or what?
Also, please don't keep bumping your thread, especially not at such short intervals.
I'm displaying the content with text and html.
-
Jul 16th, 2007, 02:58 PM
#6
Re: Help displaying data in four columns?
something like this? some old script I had lying around (in this case, it's 5 columns, rather than 4).
PHP Code:
<table border="1">
<?php
$pictures = array("picture1", "picture2", "picture3", "picture4", "picture5", "picture6", "picture7");
$ii = 0; //index for the row
$cols = 5; //number of columns in each row
$ncol = true; //whether or not to make a new column
for($i = 0; $i <= count($pictures) - 1; $i++){
$ii++;
//end a row?
if($ii > $cols){
$ii = 0; //reset row index
echo '</tr>' . "\n";
$ncol = true;
}
//start a new row?
if($ncol == true){
$ncol = false;
echo '<tr>' . "\n";
}
//display image
echo ' <td>' . $pictures[$i] . '</td>' . "\n";
//is the table finished?
if($i == count($pictures) - 1){
//finish filling the column if we need to
if($ii < $cols){
for($j = $ii; $j < $cols - 1; $j++){
echo ' <td> </td>' . "\n";
}
}
echo '</tr>' . "\n";
}
}
?>
</table>
working example of this code is here, still not sure if that's what you're looking for or not. if it is what you're looking for, it can easily be changed to work with a while() loop with mysql results rather than a for() loop with an array.
-
Jul 17th, 2007, 07:15 AM
#7
Hyperactive Member
Re: Help displaying data in four columns?
PHP Code:
<table style="width: 100%;">
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<?php
$col = 0;
$query = mysql_query("SELECT * FROM whatever WHERE whatever1 = whatever2");
while($row = mysql_fetch_array($query)) {
switch($col) {
case 0:
echo '<tr><td>'.$row[$col].'</td>';
$col++;
break;
case 3:
echo '<td>'.$row[$col].'</td></tr>';
$col = 0;
break;
default:
echo '<td>'.$row[$col].'</td>';
$col++;
break;
}
}
?>
</table>
Hope that helps
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|