skwap Posted July 30, 2011 Share Posted July 30, 2011 Friends, iam developing a small website & i used php & mysql. i have a problem small problem with sql update statement..... HERE IS MY DATA BASE TABLE id pubtoday pubtotal todayclicks totalclicks today_is 1 2.00 5.00 200 5000 29/2011/07 I want to update all user's pubtoday & todayclicks fields as 0 if the today_is date is not match with today date & also update new date. Consider Above Code (I Used) $today = date("d/Y/m"); $update = mysql_query("UPDATE `statistics` SET `pubtoday` = '0.00' , `todayclicks` = '0' WHERE `today_is`!=$today"); if($update) { $update1 = mysql_query("UPDATE `statistics` SET `today_is` = '$today' WHERE `today_is`<>$today"); } but here iam facing a problem that is pubtoday & todayclicks is setting as 0 if the date match. I need only update if the $today date is not match with db stored date. Please help me... & what is the error ?? Quote Link to comment https://forums.phpfreaks.com/topic/243242-please-help-me/ Share on other sites More sharing options...
trq Posted July 30, 2011 Share Posted July 30, 2011 $today needs to be surrounded by quotes. What datatype is the today_is field? Quote Link to comment https://forums.phpfreaks.com/topic/243242-please-help-me/#findComment-1249267 Share on other sites More sharing options...
skwap Posted July 30, 2011 Author Share Posted July 30, 2011 i changed the today_is data type to date & also made a small changes in the code (added quotes surrounded by $today)... Ya Its Got Worked ! Thank You........................... Could you please explain what may be the error occurred their ?? is it the problem of data type / in coding ? Quote Link to comment https://forums.phpfreaks.com/topic/243242-please-help-me/#findComment-1249272 Share on other sites More sharing options...
trq Posted July 30, 2011 Share Posted July 30, 2011 Stings need to be surrounded by quotes. So do dates actually. But yeah,, you should always use a date type when dealing with dates, this way if you ever need to sort by date or do any other queries based on dates you can use the date functions. Quote Link to comment https://forums.phpfreaks.com/topic/243242-please-help-me/#findComment-1249277 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.