2

I have following in the database

$checktime = mysql_query("SELECT * FROM drafts WHERE page='sched'");
while($row = mysql_fetch_array($check)){
    if($row['posted'] = date('j-n-Y'))
    {
        echo "ok";
    }
}

I'd like to compare this date against today's date. Please help me if everyone knows. thank you!

zzlalani
  • 22,960
  • 16
  • 44
  • 73
  • 2
    What goes wrong with the code you provided? (You are missing a closing `"` after your `SELECT` statement and using the wrong comparison operator `=`.) – showdev Oct 04 '13 at 21:20

1 Answers1

1

Condition is wrong, it should have two equals to signs ==

if($row['posted'] == date('j-n-Y'))

Please Note that one equal to sign is for assignment, it means that

$row['posted'] = date('j-n-Y')

The above code will assign the value of date('j-n-Y') into $row['posted']

And your assignment will do nothing but just return true, so every time it will go into the if condition block

where as the two equals to signs == are use for compression. so in your condition with double equals to, the code will only go into the if condition block when your $row['posted'] is equal to date('j-n-Y')

NOTE: mysql_* functions are Officially deprecated (as of PHP 5.5. It's likely to be removed in the next major release.)

you need to have a look at this Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
zzlalani
  • 22,960
  • 16
  • 44
  • 73