I've been having a lot of trouble recently fixing a problem i have encountered in a script i've written for a website i am creating. My problem is: I can loop a table row to display a filler (groups) for a given length up and down, but i cant make it stop after x rows down, start a new column, and then keep going with more info. I have a code which seems to be able to do this (code#2) but i cant integrate it with my code (code# 1) and make it work. What should i do?
EX: WHAT I HAVE
(CODE # 1)
A
B
C
D
E
F
G
H
I
WHAT I WANT:
(CODE 1 + 2)
A D G
B E H
C F I
------CODE # 1-------
<?
$sql="SELECT * FROM $tbl_name WHERE example='cool' AND DATE(datetime) > DATE_SUB(CURDATE(), INTERVAL 1 DAY) ORDER BY number DESC LIMIT 4";
// ORDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table>
<?php
while($rows=mysql_fetch_array($res… // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF"><a href="fillerexample"><? echo fillerexample; ?></a></td>
</tr>
<?
}
?>
</table>
--------CODE # 2------------
//the sorting function
function vert_htmltable($table){
$NbrLines = 3; // number of horizontal lines of the final table
$NbreData = count($table);
$NbrCol = 0;
if ($NbreData != 0) {
$k = 0;
$return.="<table><tr>";
while ($k < $NbreData){
$return.="<td><table>";
for ($i=1; $i<=$NbrLines; $i++){
if ($k < $NbreData){
$return.="<tr><td>";
$return.=$table[$k]."</td></tr>";
$k++;
}
if ($i == $NbrLines){
$return.="</table></td>";
}
}
$NbrCol++;
}
$return.="</tr></table>";
}
return $return;
}
//we process your "results" vars table ( keep it as a table as you did first )
$vert_table=vert_htmltable($result);
//showing result
echo $vert_table;
EX: WHAT I HAVE
(CODE # 1)
A
B
C
D
E
F
G
H
I
WHAT I WANT:
(CODE 1 + 2)
A D G
B E H
C F I
------CODE # 1-------
<?
$sql="SELECT * FROM $tbl_name WHERE example='cool' AND DATE(datetime) > DATE_SUB(CURDATE(), INTERVAL 1 DAY) ORDER BY number DESC LIMIT 4";
// ORDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table>
<?php
while($rows=mysql_fetch_array($res… // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF"><a href="fillerexample"><? echo fillerexample; ?></a></td>
</tr>
<?
}
?>
</table>
--------CODE # 2------------
//the sorting function
function vert_htmltable($table){
$NbrLines = 3; // number of horizontal lines of the final table
$NbreData = count($table);
$NbrCol = 0;
if ($NbreData != 0) {
$k = 0;
$return.="<table><tr>";
while ($k < $NbreData){
$return.="<td><table>";
for ($i=1; $i<=$NbrLines; $i++){
if ($k < $NbreData){
$return.="<tr><td>";
$return.=$table[$k]."</td></tr>";
$k++;
}
if ($i == $NbrLines){
$return.="</table></td>";
}
}
$NbrCol++;
}
$return.="</tr></table>";
}
return $return;
}
//we process your "results" vars table ( keep it as a table as you did first )
$vert_table=vert_htmltable($result);
//showing result
echo $vert_table;
Comment