Hi i had a database table which stores images in columns.

ie

idno + image name + name
1      | lal.jpg            |  raj
2      | lal2.jpg          |  raj2
3      | lal3.jpg          |  raj3 .....

Now I need to show this images and these names in a page as 3 columns....

I wrote the code as..

$result=mysql_query("SELECT * from table where approved='yes'").....
while($show=mysql_fetch_array($result)) {

I need to show the result as 3 columns like 3 images in a row...

Please Help me....
Thanks in advance
Rajeesh

Recommended Answers

All 3 Replies

try to do some thing like this:

<?php
$i=0;
echo"<table><tr>";
$result=mysql_query("SELECT * from table where approved='yes'").....
while($show=mysql_fetch_array($result)) {
$imagename=$show['image_name']; 
$name=$show['name'];
echo"<td><img src='folderwherepicarestored/$imagename' width='200' height='150'><br> $name</td><td>";

if($i==3){
echo"</td></tr>"
}
echo"</table>";
?>

Thanks for your support... Now where i need to do the increment of i ?
Please help;

value of $i u need to put before the the while loop starts as i wrote.
and after u`ve displayed 3columns u need to reset the value again to zero.
Check well the code it works.

<?php
$i=0;
echo"<table><tr>";
$result=mysql_query("SELECT * from table where approved='yes'").....
while($show=mysql_fetch_array($result)) {
$imagename=$show['image_name']; 
$name=$show['name'];
echo"<td><img src='folderwherepicarestored/$imagename' width='200' height='150'><br> $name</td><td>";
 
if($i==3){
echo"</td></tr>"
$i=0;//reseting the value to zero again
}
echo"</table>";
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.