0

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

Attachments Photo.png 6.97 KB
4
Contributors
10
Replies
22
Views
7 Years
Discussion Span
Last Post by dev.vini
Featured Replies
  • 1

    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. Read More

0

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 ?

0

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");
?>
1

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.

1

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

0

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.

0

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 :)

Edited by metalix: n/a

0

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.

Edited by doctorphp: n/a

0

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.

0

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.

Edited by doctorphp: n/a

0
<?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

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.