Page 1 of 1

Posted: Wed Aug 18, 2004 11:10 am
by feyd
JAM | changed to code instead of php tags.
feyd | changed back to php tags now that they are working again.

Code: Select all

<?php
$usr = "****"
$pwd = "*****";
$db = "******";
$host = "localhost";

# 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 portfolio ";
$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 = 3;
for($x = 0; $row = mysql_fetch_array($retid); $x++)
{
if($x % $rowmax == 0)
$output .= "<tr>\n";
$pic_ref = $row["pic_ref"];
$pic_name = $row["pic_name"];
$img_name = $row["img_name"];
$pic_desc = $row["pic_desc"];
$sub_date = $row["sub_date"];
$photographer = $row["photographer"];

$output .= "<td><img src =\"pics/$img_name\">$pic_name</td>";
if($x % $rowmax == $rowmax - 1)
$output .= "\r</tr>\n\n";
}

if($left = (($howmany + $rowmax - 1) % $rowmax))
$output .= '<td colspan="' . $left . '">&nbsp' . ";</td>\n</tr>\n\n";

$output .= "</table>\n\n";

$output .= "</DT></P>";

$output .= '</BODY>
</HTML>';

echo $output;
?>

Posted: Thu Aug 19, 2004 8:34 am
by reh
Thank you soooo much for doin the code for us, just trying to understand it now, but it works and it is exactly what i needed.

thanks again

I Reh

Re: [SOLVED] PHP & MySQL formatting problem

Posted: Tue Sep 16, 2008 2:18 pm
by Weasel5-12
wow, very very similar to a situation im in myself !

cheers bro !! this is great (although i dont fully understand how it all works... yet) :D

Re: [SOLVED] PHP & MySQL formatting problem

Posted: Wed Nov 11, 2009 5:44 pm
by starram
Hello feyd

I have choosed following line from the code you wrote.

I am not able to understand how this line will behave?

" for($x = 0; $row = mysql_fetch_array($retid); $x++) "

Or is it incorrect?

Please update.
Regards
Ram

Re: [SOLVED] PHP & MySQL formatting problem

Posted: Thu Dec 02, 2010 12:25 am
by imadbaloch
<?php $sql="select id from table_name where id=$_GET['id']";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)){
?><tr><td><img scr="images/<?php echo $row['image']?>"></td></tr><?php } ?>