I am able to display the images that i am retrieving from the database as a list. But i want to know how i will be able to display the same images as a grid or table.
I have posted my code below.Can you please let me know how to alter the code to get it in a griew or table format. Any help will be appreciated.





  die('could not connect'.mysql_error());
echo "Connection established";

$query = ("SELECT * FROM Books");

                $result = mysql_query($query);

                while($dog = mysql_fetch_array($result)){

                    $petname = $dog ['BookName'];

                    echo "<P>" . $dog['BookName'] ."</P>";

                    echo "<img src='".$dog['Photo']."' alt='dog' width='200' height='200' />"; 

the best way to accomplish this is to use css.

#thumb {
clear : both;
width : 100%;
margin-left : 0;

#thumb ul {
width : 100%;

#thumb ul li {
display : inline;
font-family : arial;
float : left;
padding-right : 5px;
width: 210px; 
height : 280px;


#thumb ul li img {
float : left;
width : 200px;
height : 200px;
border : #ccc solid 1px;
padding : 2px;


The php code for image can be written like this

echo '<div id="thumb"><ul>';

while($dog = mysql_fetch_array($result)){
$petname = $dog ['BookName'];
echo '<li><P>' . $dog['BookName'] .'</P>';
echo '<img src="'.$dog['Photo'].'" alt="dog" />';
echo '</li>';

echo '</ul></div>';

You should update your mysql query to PDO or mySQLI. Don't forget to add the proper html tags for the css file.

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.