Shoutbox

simple php help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: simple php help (/showthread.php?tid=54641)

simple php help by spokes on 01-05-2006 at 06:08 PM

OK, so on my site, i have an image gallery which gets the image information from a mysql database, then i use php to display the information

but ATM i have them all going down in a list like

#
#
#
#

# representing image

but i would like it in a table with 4 columns that creates a new row on every multiple of 4
eg
# # # #
# # #

etc

how can i do this in php, thanks in advance

here's my code, yes the html is bad

code:
$i=0;
while ($i < $num) {

$Desc=mysql_result($result,$i,"Desc");
$File=mysql_result($result,$i,"File");
$Type=mysql_result($result,$i,"Type");
$Date=mysql_result($result,$i,"Date");

if ($Type=="vid") {
echo "<div align='center'><img src='Media/video.jpg'><br />Description : $Desc<br /><br /><a href='Media/$File' target='_blank'>View Video</a><br />Added On $Date<br />-----<br /></div><br /><br />";
} else {
echo "<div align='center'><img src='Media/$File' width='200' height='150' border='1'><br />Description : $Desc<br /><br />Filename : $File<br /><br /><a href='Media/$File' target='_blank'>Click to see full size picture</a><br />Added On $Date<br />-----<br /></div><br /><br />";
}
$i++;
}
?>


RE: simple php help by L. Coyote on 01-05-2006 at 06:26 PM

Small sample to be used with mysql_fetch_assoc:

code:
<?
$cols = 4;
$now = 0;
echo '<table><tr>';
    while($d = mysql_fetch_assoc($sql_query)) {
    echo '<td>'.$d['column1'].'</td>';
    $now++;

        if($now == $cols) {
        echo '</tr><tr>';
        $now = 0;
        }
    }
echo '</tr></table>';
?>

RE: simple php help by spokes on 01-05-2006 at 06:38 PM

quote:
Originally posted by Leo
$cols = 4;
$now = 0;
echo '<table><tr>';
while($d = mysql_fetch_assoc($sql_query)) {
echo '<td>'.$d['column1'].'</td>';
$now++;

if($now == $cols) {
echo '</tr><tr>';
$now = 0;
}
}
echo '</tr></table>';


thanks, it works :D