Hi All.

I am trying to display images using the while loop but I want the pictures to be displayed like this.

The only thing is, I don't know how to do it. Any help would be much appreciated.

Thank you in advance
Cameron

You can use a table, or use div's with css positioning. It depends a bit on what your page html looks like. What is your code ?

You can use a table, or use div's with css positioning. It depends a bit on what your page html looks like. What is your code ?

This is the page where you can view the pictures but I would like it to look like the picture I attached with my original post.

<?php
require("check_session.php");
$albumid = $_GET['album'];

$sql = mysql_query("SELECT * FROM items WHERE userid='".$_SESSION['id']."' AND albumid='$albumid'");




?>
<font face='arial' size='4'><b><u>Note</u></b><br />When clicking on the public address link, make sure you only give it to people you know and trust.</font><p>
<?php $num22 = mysql_num_rows($sql);

if($num22>1)
{
	?>
<form action='changecover.php?album=<?php echo $albumid; ?>' method='post'>
Change album cover to: <select name="newcover"><?php 

while($row2 = mysql_fetch_assoc($sql))
{
echo "<option value=\"".$row2['location']."\">".$row2['name']."</option>";
}
?></select><input type='submit' name='changecover' value='Change Cover' /></form>
<?php
}
else echo "";

$id = $_SESSION['id'];

$album = mysql_query("SELECT name FROM albums WHERE id='$albumid'");
$albumarray = mysql_fetch_assoc($album);


$image = mysql_query("SELECT * FROM items WHERE userid='$id' AND albumid='$albumid'");


if(mysql_num_rows($image)<=0)
die( "<font color='#FF0000'><br><br><b>No images uploaded yet.<br /><a href='upload.php'>Upload One?<br /></a></font><br><font size='4'><a href='albums.php'>Back</a>");

echo "<br><br><font face='arial' size='4'>Album: ".$albumarray['name']."<table width='100%' cellpadding='7'>";
while ($row = mysql_fetch_assoc($image))
{
	
	echo"
	<tr>
	<td width='220'>
	<a href='viewpicture.php?imageid=".$row['id']."'><img src='".$row['location']."' width='265' height='200' border='0'></a><br>
	</td>
	<td><font face='arial' size='4'>
	<b><a href='viewpicture.php?imageid=".$row['id']."'>".$row['name']."</a></b></font><br>
	<font face='arial' size='3'>".$row['description']."<br>
	<a href='deletepicture.php?picture=".$row['id']."'>Delete</a><br />
	<a href='publicimage.php?picture=".$row['pubid']."' target='_blank'>Public Address</a>
	
	
	<form method='post' name='change_cover' action='change_cover.php?album=$albumid'>
	
	
	</td>
	</tr>";
}
echo "</table><font size='4'>";
?>


<br />
<a href='upload.php'>Upload another picture</a>
<br />
<a href='albums.php'>Back</a>

<?php
include("design/footer.php");
?>

Because within the loop you add every image in it's own <tr><td> they will show below one another. You could only open a <tr> when index % 3 == 0 so you get three <td>'s in a single row.

here is a basic code

$a = 1;
echo '<table><tr>';
while($row = mysql_fetch_assoc($image)){
    if($a <= 3){ //number of cells in row
    echo '<td>'.$row['image'].'</td>';
    }
    else {
    echo '</tr>\n<tr>'.'<td>'.$row['image'].'</td>';
    }
$a++;
}
echo '</tr></table>';

Hope this helps :)

There is a tutorial on printing tables here

here is a basic code

$a = 1;
echo '<table><tr>';
while($row = mysql_fetch_assoc($image)){
    if($a <= 3){ //number of cells in row
    echo '<td>'.$row['image'].'</td>';
    }
    else {
    echo '</tr>\n<tr>'.'<td>'.$row['image'].'</td>';
    }
$a++;
}
echo '</tr></table>';

Hope this helps :)

There is a tutorial on printing tables here

Ok thank you so, so much for your help.

I really appreciate it.

sorry just realised that code won't work.

$a = 1;
echo '<table><tr>';
while($row = mysql_fetch_assoc($image)){    
if($a <= 3){ //number of cells in row    
echo '<td>'.$row['image'].'</td>';  
 $a++;
}    
else {    
echo '</tr>\n<tr>'.'<td>'.$row['image'].'</td>';
$a = 1; 
    }
}
echo '</tr></table>';

that will work better.
$a determines where it is at in a row.
at the end of the row it needs to reset to 1 :)

sorry just realised that code won't work.

$a = 1;
echo '<table><tr>';
while($row = mysql_fetch_assoc($image)){    
if($a <= 3){ //number of cells in row    
echo '<td>'.$row['image'].'</td>';  
 $a++;
}    
else {    
echo '</tr>\n<tr>'.'<td>'.$row['image'].'</td>';
$a = 1; 
    }
}
echo '</tr></table>';

that will work better.
$a determines where it is at in a row.
at the end of the row it needs to reset to 1 :)

Thanks but it doesn't work.

if your recieving an error please post it here. you may not be connecting to your database correctly.
have you included $image=mysql_query.....

otherwise look at your source code -> when you open the page in the browser, and see whats happening.

if your recieving an error please post it here. you may not be connecting to your database correctly.
have you included $image=mysql_query.....

otherwise look at your source code -> when you open the page in the browser, and see whats happening.

Im am not recieving any errors and it is connecting to the database but all it does is shows two pictures and doesn't show the name of the image. Here is what I did to your code.

$a = 1;
echo '<table><tr>';
while($row = mysql_fetch_assoc($image)){    
if($a <= 3){ //number of cells in row    
echo '<td><img src="'.$row['location'].'" width="260" height="160"></td>';  
 $a++;
}    
else {    
echo '</tr>\n<tr>'.'<td>'.$row['name'].'</td>';
$a = 1; 
    }
}
echo '</tr></table>';

Thanks for your help so far.

<?php
        while($c = mysql_fetch_array($b))

        {echo 

            "<tr> 
            <td width=\"800\" align='center'>"?><img src=\"images/<?php echo $c['photo'];?>\" height="60" width="100"> <?php echo "</td> 
            <td>CHANGE</td>
            </tr> ";
    }
?>

this is the way to show the image in the tr
untill loop is running