0

Hello
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.

booklist.php

<?php


$database="login";


$con=mysql_connect("localhost","root","");
if(!$con)
{

  die('could not connect'.mysql_error());
}
mysql_select_db("$database",$con);
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' />"; 
                }
            ?>
2
Contributors
1
Reply
14
Views
3 Years
Discussion Span
Last Post by veedeoo
0

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.

Edited by veedeoo: more info. added

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.