Forum Moderators: coopster
Currently it just displays the image,title and date in one row and then the other images in next row
However i want to create two columns and display all the images in following fashion
r1c1 image1 then r1c2 image2 then r2c1 image3 then r2c2 image4 and so on...
what to do?
echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
while($row = mysql_fetch_array($sql))
{
$name= $row['name'];
$tcheck=$safeurl->make_safe_url($row['title']);echo "<tr><td width='25%'>";
echo ' <img src="/addons/class.upload/test/'.$name.'" />';
echo '<br />';
echo '<a href="/'.$sid.'/'.$catid.'/'.$row['id'].'/0/'.$tcheck.'"><strong>' .$row['title'].'</strong></a>';
echo '<br />';
echo " [ ";
echo date("d/m/Y", $row['date'])."";
echo " ] </td></tr>";
}
echo "</table>";
I know very little about php, but from what I see in your code, it is set to write one row with a column width of 25%. Without the php:
<tr>
<td width="25%">
</td>
</tr>
This format is only going to give you one column. PHP aside, for two columns you need:
<tr>
<td width="whatever">
</td>
<td width="whatever">
</td>
</tr>
Forgive me if I am off the mark here, but the single column is what I see your current output resulting in.
Hope this helps some.
Marshall
I printed the each photo in a table nested in a div tag.
this comes in while loop
while($row=mysql_fetch_array($result)){
$img_path=$row['img_path'];
<NOBR>
<div>
<table>
<tr><td><img src='<?php echo $img_path;?>'></td></tr>
</table>
</div>
</NOBR>
}
Please Note: your outermost table must have a fixed width.
If you want to do the table in a way that it prints two columns with data from database and you don't have a set amount of columns, you could do something like this:
<table>
<tr>
$i = 0;
while($row = mysql_fetch_array($sql))
{
*Your PHP Script here, but leave out the last </tr>*
$d = $i % 2; // division remainder
// check if the current column is dividable by two
if( $d == 0 && $i!= 0 ) {
echo "</tr><tr>"; // ends your row and starts a new one
}
$i++;
}
</tr>
</table>
Hope this helps.
Try this. Done on the fly, so not tested but I hope you'll understand the way I have proceeded.
Tomda
// GET TOTAL NUMBER OF PIC
$count_pic=mysql_num_rows($sql);
// CHECK IF TOTAL NUMBER IS EVEN OR UNEVEN
$qty = "2"; // BECAUSE 2 COLUMNS
if ($count_pic % $qty!= 0) {$even="0";} else {$even="1";}
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
$icount = "1";
while($row = mysql_fetch_array($sql)) {
$name= $row['name'];
$tcheck=$safeurl->make_safe_url($row['title']);
// OPEN TR IF ICOUNT IS AN UNEVEN NUMBER
if($icount % $qty!= 0) {echo '<tr>';}
echo '<td width="25%"><img src="/addons/class.upload/test/'.$name.'" /><br /><a href="/'.$sid.'/'.$catid.'/'.$row['id'].'/0/'.$tcheck.'"><strong>' .$row['title'].'</strong></a><br /> [ '.date("d/m/Y", $row['date']).' ] </td>';
// CLOSE TR IF ICOUNT IS AN EVEN NUMBER
if($icount % $qty == "0") {echo '</tr>';}
}
// IF COUNT_PIC IS UNEVEN, THEN ADD EMPTY <td></td>
if($even=="0") {echo '<td></td></tr>';}
echo '</table>';