Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii experts

i am new to php

now i am working on one project in that i want to bind images on html page.image path is stored in database

i am able to bind image each in new row but i want to show it as 3 images in each row.

so will any one help me how should it be possible

my code is as below

PHP
include 'database.php';
	
		$query	=	"select * from image_upload";
		$select	=	mysql_query($query);
		if($select)
		{
			echo "<table border='1' align='center'><tr><th width='150px' height='50px' align='center'>Image</th><th width='150px' height='50px' align='center'>Name</th><th width='150px' height='50px' align='center'>Remove</th></tr>";
			while ($row = mysql_fetch_assoc($select))
			{	
				
				$id = $row['id'];
				$url=$row['img_url'];
				
				//echo "<td width='150px' height='100px' align='center'>";
				//echo $id;
				echo "<tr></td><td width='150px' height='100px' align='center'>";
				echo  "<img src='$url' height='100p' width='150px'/>";
				echo  "</td><td width='150px' height='100px' align='center'>";
				echo  $url;
				echo "</td><td width='150px' height='100px' align='center'>";
				echo "<a href='delete_edit.php?id=$id' class='button' id='btn_re'>Remove</a>";
				echo "</td></tr>";
			}	
			echo "</table>";
		}
Posted

Hello,

If I have understood your problem correctly then may be following code should help you achieve what you want. i.e. It will display 3 images per row with hyperlink to delete them.
PHP
include 'database.php';
    
$query    =    "select * from image_upload";
$select    =    mysql_query($query);
$cntr   = 0;
$imgs   = "";
if($select)
{
    echo "<table border='1' align='center'><tr><th width='150px' height='50px' align='center'>Image</th>" . 
            "<th width='150px' height='50px' align='center'>Name</th><th width='150px' height='50px' align='center'>Remove</th></tr>";
    while ($row = mysql_fetch_assoc($select))
    {    
        $id = $row['id'];
        $url = $row['img_url'];

        if ($cntr == 3) {
        {
            echo "<tr>";
            echo $imgs;
            echo "</tr>";
            $imgs = "";
            $cntr = 0;
        } else {
            $imgs = $imgs . "<td width='150px' height='100px' align='center'>".
                    "<a href='delete_edit.php?id=$id'><img src='$url' width='150px' height='100px'/></a></td>";
        }
        $cntr = $cntr + 1;
    }
    if (strlen($imgs) > 0) {
        echo "<tr>";
        echo $imgs;
        echo "</tr>";
    }
    echo "</table>";
}

Regards,
 
Share this answer
 
v2
Yesterday I tried to post an example for you, but I failed because of .... Anyway, I am trying to post it again now. Hope you can extract your required code from it

PHP
$i=45;			//number of column in row
$j=0;
$total=850;		//number of item to be showed

echo "<TABLE>";
while($j<$total)
{
	if($j%$i==0)
	{
		echo "<TR>\n";
	}
	echo "<td style='border:1px solid gray'>".($j+1)."</td>\n";
	$j++;
	if($j%$i==0)
	{
		echo "</TR>\n";
	}
}
for($k=0;$k<$i-$j%$i && $j%$i!=0;$k++)
{
		echo "<td style='border:1px solid gray'></td>\n";
}
echo "</TABLE>";


You can modify it the way you want :D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900