[SOLVED] PHP & MySQL formatting problem

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

Post Reply
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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;
?>
Last edited by feyd on Sat Apr 02, 2005 8:46 am, edited 1 time in total.
reh
Forum Newbie
Posts: 9
Joined: Tue Aug 17, 2004 10:35 am

Post 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
User avatar
Weasel5-12
Forum Commoner
Posts: 37
Joined: Tue Sep 16, 2008 6:58 am

Re: [SOLVED] PHP & MySQL formatting problem

Post 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
User avatar
starram
Forum Commoner
Posts: 58
Joined: Thu Apr 10, 2008 1:27 am
Location: India
Contact:

Re: [SOLVED] PHP & MySQL formatting problem

Post 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
imadbaloch
Forum Newbie
Posts: 1
Joined: Thu Dec 02, 2010 12:09 am

Re: [SOLVED] PHP & MySQL formatting problem

Post 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 } ?>
Post Reply