PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
psurrena
Forum Contributor
Posts: 355 Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY
Post
by psurrena » Thu Jan 05, 2006 11:37 am
Hello,
I would like to format the results pulled from my query. Right now it just lists the images since all I've included is the <br /> tag. My question is, how would I specify three images across and then start a new line?
Thanks,
-Pete
My code is as follows:
Code: Select all
<?php
include '../library/config.php';
include '../library/opendb.php';
$query = "SELECT id, name FROM upload2";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<img src="../upload/<?=$name;?>" /> <br />
<?php
}
}
include '../library/closedb.php';
?>
psurrena
Forum Contributor
Posts: 355 Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY
Post
by psurrena » Thu Jan 05, 2006 12:01 pm
Thanks! The first post worked great. For other people, here is how my code looks:
Code: Select all
<?php
$usr = "*******";
$pwd = "*******";
$db = "*******";
$host = "*******";
# connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
$output = '<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>';
# setup SQL statement
$SQL = " SELECT * FROM gallery ";
$SQL = $SQL .
# execute SQL statement
$retid = mysql_db_query($db, $SQL, $cid) or die(mysql_error());
# display results
$output .= "<P><DT><B>$category</B><BR>\n\n";
$output .= "<table>\n\n";
$howmany = mysql_num_rows($retid);
$rowmax = 2;
for($x = 0; $row = mysql_fetch_array($retid); $x++)
{
if($x % $rowmax == 0)
$output .= "<tr>\n";
$img_name = $row["name"];
$output .= "<td><img src =\"../upload/$img_name\">$img_name</td>";
if($x % $rowmax == $rowmax - 1)
$output .= "\r</tr>\n\n";
}
if($left = (($howmany + $rowmax - 1) % $rowmax))
$output .= '<td colspan="' . $left . '"> ' . ";</td>\n</tr>\n\n";
$output .= "</table>\n\n";
$output .= "</DT></P>";
$output .= '</BODY>
</HTML>';
echo $output;
?>