获取数据库中存在的所有图像ID并显示它们(MySQL \ PHP)

I've read all about this in other questions asked here at stackoverflow but none have gave me answers to my situation. Here is what i have:

  • Database of the Images ID and Location. (database has two columns ID and URL) the ID is incremental and same name as the image name. so in the database it shows as follows: Database Overview

now my question is how can i retrieve those images from the database? I know how to display them in HTML using the php echo. but my problem is how to get them out of the database in order? I'm thinking about something maybe like while(still images id) Or I can use count of the number of rows then go one by one calling them (which i think is too heavy)

Any help would be great figuring this one out!

Thank you :)

You'll need to connect to the database and query it for the images in your table. (tbl_name must be replaced by the name of your MySQL table containing the images)

$qry = mysql_query("SELECT URL from tbl_name ORDER BY URL");

while ($row = mysql_fetch_assoc($qry)) {
    echo $row['URL'];
}

See the excellent tutorials on W3Schools for details: http://www.w3schools.com/php/php_mysql_connect.asp

$sql = "SELECT URL FROM TableName";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["URL"];
    }
}