Reputation: 21
I am using MySQL and I think it has something to do with Id's. I want every new image I upload to show up first in a order. Here is my code:
This allows the images to display:
<?php
$db = mysqli_connect("localhost", "root", "", "photos");
$sql = "SELECT * FROM images";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($result)) {
echo "<a href='uploads/".$row['image']."'> ";
echo "<img id='img_div' src='uploads/".$row['image']."'/>";
echo "</a>";
}
?>
Here is my image structure:
CREATE TABLE `images` (
`id` int(11) NOT NULL,
`image` varchar(200) NOT NULL,
`text` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `images` (`id`, `image`, `text`) VALUES .....
ALTER TABLE `images`
ADD PRIMARY KEY (`id`);
ALTER TABLE `images`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=129;
Upvotes: 0
Views: 38
Reputation: 340
$sql = "SELECT * FROM images ORDER BY id DESC";
Should do the trick!
Upvotes: 2