Beste mensen,

Hoe kan ik het beste de eerst en laatste datum uit een tabel in een database halen? Ik heb een tabel met een veld(tijd) die Timestamp als format heeft. Het aantal records lukt me al met:

<?php
include ('includes/dbConnect.php');
$result = mysqli_query($dbCon,"SELECT
*
FROM
test");

$tellenr = mysqli_num_rows($result);

echo $tellenr;
?>


<?php
include ('includes/dbConnect.php');
$result = mysqli_query($dbCon,"SELECT MIN(tijd) oudste, MAX(tijd) nieuwste FROM test");

if($row = mysqli_fetch_assoc($result))
{
echo $row['oudste'] . $row['nieuwste'];
}
?>
Super! Dankjewel!
Als je de hele records nodig hebt dan zou ik het maar in tweeën doen

<?php
include ('includes/dbConnect.php');

$result = mysqli_query($dbCon,"SELECT * FROM test ORDER BY tijd LIMIT 1");

if($row = mysqli_fetch_assoc($result))
{
print_r($row);
}

$result = mysqli_query($dbCon,"SELECT * FROM test ORDER BY tijd DESC LIMIT 1");

if($row = mysqli_fetch_assoc($result))
{
print_r($row);
}
?>

Reageren