I am making an image website and I need help with timestamp sorting. I have about 5 different SQL queries to get information from the database. Each one of these queries get the timestamp.
What I want to do is get it from the database, and sort the images from all of the queries with a foreach loop. This may sound confusing, just comment if you don't understand.
$images = array();
$stmt = $conn->prepare("SELECT images.*, group_images.* ORDER BY `timestamp` DESC");
$stmt->execute();
while ($images_row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$images[] = array(
'image_id' => $images_row['image_id']);
}
return $images;
foreach($images as $image) {
echo $image['image_id'];
echo '<br/>';
}
That is a query I attempted to try which turned out not to work.
Error:
$images = valley_images();
$sorted_data = array();
foreach($images as $key => $value) {
if ($key == 'timestamp') {
$sorted_data[$value][] = $images;
}
}
ksort($sorted_data);