I’ve got 12 rows in mysql that match this query, but I’m only wanting to examine the row with the most recent date and capture only that date (timeStamp). Despite setting the “LIMIT 1” (and I’ve tried “LIMIT 0, 1”), it still examines all the rows and pulls timeStamp for each row.
$result = mysql_query("SELECT timeStamp FROM postings WHERE city='$city' and STR_TO_DATE('$date', '%a, %d %M %Y') > timeStamp LIMIT 1");
while($row = mysql_fetch_array($result)) {
$mysqldate = $row['timeStamp'];
$mysqldate = strtotime($mysqldate);
$mysqldate = date('Y-m-d', $mysqldate);
$date = strtotime($date);
$date = date('Y-m-d', $date);
echo "mysql date is ".$mysqldate. " and date is ".$date;
echo '<br>';
if ($mysqldate > $date) {
echo "mysql date is greater";
}
}
Here’s the output it’s giving:
mysql date is 2011-11-27 and date is 2011-12-01
mysql date is 2011-11-27 and date is 2011-11-29
mysql date is 2011-11-26 and date is 2011-11-27
mysql date is 2011-11-22 and date is 2011-11-26
mysql date is 2011-11-19 and date is 2011-11-22
mysql date is 2011-11-17 and date is 2011-11-19
mysql date is 2011-11-15 and date is 2011-11-17
mysql date is 2011-11-15 and date is 2011-11-17
mysql date is 2011-11-09 and date is 2011-11-15
mysql date is 2011-10-26 and date is 2011-11-09
mysql date is 2011-10-26 and date is 2011-11-09
mysql date is 2011-10-22 and date is 2011-10-26
I’m expecting the mysql date to be the same for every row.. but as you can see, it’s pulling it from each individual row. Any idea why?
Thanks for any assistance.
You should try:
Anyway if you feel you just want one row (MySQL should give you just one!) you could not use
but just
$row = mysql_fetch_array($result)