PDA

View Full Version : Adding images into a Layout...



Moshambi
09-23-2008, 05:56 AM
Hey guys,

I am getting images from what a user uploads and my problem is that when I display them they get displayed in one column going down the page. I would like them to be displayed in 2 columns though. Usually this would be a simple task for me but since there is text that goes with each picture it is throwing me off. Here is the code I wrote:



<?php
$sql = "SELECT * FROM pictures WHERE username = '".$_SESSION['user']."'";
$result = mysql_query($sql) or die (mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href='".$row['picurl']."'><img src='" . $row["picurl"] . "' width='300' height='300'/></a><br />";
echo $row["pictext"] . "<br /><br />";
}
?>


Thanks for any of your thoughts!

Nile
09-23-2008, 12:05 PM
<?php
$sql = "SELECT * FROM pictures WHERE username = '".$_SESSION['user']."'";
$result = mysql_query($sql) or die (mysql_error());
$i=0;

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
++$i;
if($i==2){ $i = 0; }
echo "<div ".($i==1) ? "style='float:left'" : ""."><a href='".$row['picurl']."'><img src='" . $row["picurl"] . "' width='300' height='300'/></a><br />";
echo $row["pictext"] . "<br /><br /></div>";
}
?>

Thing that should work, didn't test it though.
Btw, I added a div in there.
If this script doesn't work send me over ALL of your code.

Moshambi
09-23-2008, 05:14 PM
Dude awesome! I can't believe I didn't think about putting it in a floated div. I had to take out the .($i==1) ? and : ""." cuz it was making it just display the text. But when I removed that it worked exactly how I wanted it to. Thank you so much Nile!

Nile
09-23-2008, 10:01 PM
Your welcome. :) That's what genies are for, lol jk.