Forum Moderators: open
$current = SELECT payendDate FROM lab_payroll ORDER BY payendDate DESC, LIMIT 1
This gives me one record with the most recent date in the database.
Now I want to find all the records in the database whose payendDate equals that date. How do I do that?
I've tried
$results=SELECT * FROM lab_payroll WHERE payendDate=$current
That seems logical, but it doesn't work. Help!
If you are running MySQL >= 4.1 you can use a subquery:
SELECT * FROM lab_payroll WHERE payendDate = (SELECT MAX(payendDate) FROM lab_payroll)
If not, then you could fetch the maximum date value from your result set in the first query and use it as a variable in the next query.
$query = 'SELECT MAX(payendDate) AS currentPayendDate FROM lab_payroll';
$rows = mysql_query [php.net]($query);
if ($row = mysql_fetch_assoc [php.net]($rows)) {
$current = $row['currentPayendDate'];
$query = "SELECT * FROM lab_payroll WHERE payendDate = $current";
$rows = mysql_query($query);
while ($row = mysql_fetch_assoc($rows)) {
// process the result set
}
}