I always get confused when working with dates in PHP and MySQL. I looked through other posts, but couldn't find a solution,
I have a simple blog stored in a database that echos records when queried. I get multiple rows with multiple entries, but the date is the same on all of them.
The dates are stored with MySQL timestamp in a column called 'TimeStamp' and are formatted this way in the database: 2011-12-29 21:16:55 (for example).
Here's the query:
$set_select_sql = "SELECT *
FROM `table`
ORDER BY `table`.`TimeStamp` DESC
LIMIT 0 , 30";
$set_query = mysql_query($set_select_sql);
$HowMany=mysql_num_rows($set_query);
$time = date("g:i a", strtotime(mysql_result($set_query,0,'TimeStamp')));
$date = date("F j, Y ", strtotime(mysql_result($set_query,0,'TimeStamp')));
$blogpost = mysql_result($set_query,0,'blogpost');
mysql_data_seek($set_query, 0);
$r = 0;
while ($r <= $HowMany) {
$row = mysql_fetch_assoc($set_query);
if ($row == FALSE) {
} else {
extract($row);
echo "It was $time on $date when I posted this.<br/>";
echo "$blogpost"
}
$r++
Why am I only getting one date? What am I missing?
Thanks!
if($row == FALSE){}withif($row !== FALSE)so you don't have to put your logic in anelse