Jeffro Posted December 3, 2011 Share Posted December 3, 2011 This kind of borders on php as much as mysql, but I think the mysql part is what's hanging me up. This works great in my php page: $query = "INSERT IGNORE INTO postings (title, description, timeStamp) VALUES ( '$title', '$description', STR_TO_DATE('$date', '%a, %d %M %Y %H:%i:%s'))"; So now.. for any new records, I want to compare the php $date against the mysql date (column called dateStamp with a type of datestamp). I tried adding this: $querycheck = "SELECT 1 FROM postings WHERE city='$city' and STR_TO_DATE('$date', '%a, %d %M %Y %H:%i:%s') > timeStamp LIMIT 1"; if ($querycheck === true) { $query = "INSERT IGNORE INTO postings (title, description, timeStamp) VALUES ( '$title', '$description', STR_TO_DATE('$date', '%a, %d %M %Y %H:%i:%s'))"; mysql_query($query) or die( "<br>Query string: $query<br>Caused error: " . mysql_error() ); } It seems to be evaluating the expression because.. if I run my php 2x in a row, it inserts about 20 dates the first time.. and 0 the second time. The problem though.. I'll then order by dateStamp desc for that city only... delete the highest date, rerun my php page and it still inserts 0 results, even though $date is higher than any other result in the mysql table at that point. Any ideas? Quote Link to comment Share on other sites More sharing options...
fenway Posted December 4, 2011 Share Posted December 4, 2011 If you're trying to UPDATE data, then use UPDATE, not INSERT. Otherwise, the first thing that jumps to mind that that you're checking for the query being successfully executed, not returned. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.