What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » simple php help

simple php help
Author: Message:
spokes
Full Member
***

Avatar
I <3 Rollerblading

Posts: 423
Reputation: 10
34 / Male / Flag
Joined: May 2004
O.P. simple php help
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++;
}
?>


[Image: sig15ws.png]
01-05-2006 06:08 PM
Profile E-Mail PM Web Find Quote Report
L. Coyote
Senior Member
****

Avatar
Captain Obvious

Posts: 981
Reputation: 49
39 / Male / Flag
Joined: Aug 2004
Status: Away
RE: simple php help
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>';
?>

Hack, hack, hack!
Finally became a Systems Analyst! :spam:

01-05-2006 06:26 PM
Profile PM Find Quote Report
spokes
Full Member
***

Avatar
I <3 Rollerblading

Posts: 423
Reputation: 10
34 / Male / Flag
Joined: May 2004
O.P. RE: simple php help
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

[Image: sig15ws.png]
01-05-2006 06:38 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On