SirChick Posted October 27, 2007 Share Posted October 27, 2007 Hey, Im trying to create a script that will echo something after 6 months of the previous event. So that the echo will only occur half annual. This is what i got but i dont think its correct cos i think it's comparing by days and not months....and I don't know how to change it : <? //get last event date and now date $GetDate = mysql_query("SELECT DATEDIFF(NOW(), FieldUpdate) AS MonthsOld FROM countries WHERE CountryID='1'") or die(mysql_error()); $monthsoldrow = mysql_fetch_assoc($GetDate); //if its been 6 months echo the secret button If ($monthsoldrow >6){ Echo' <input type="submit" id="Button1" name="Button1" value="Update" style="position:absolute;left:667px;top:180px;width:75px;height:24px;z-index:20"> '; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75013-6-months-old/ Share on other sites More sharing options...
wildteen88 Posted October 27, 2007 Share Posted October 27, 2007 The following is incorrect: $monthsoldrow = mysql_fetch_assoc($GetDate); //if its been 6 months echo the secret button If ($monthsoldrow >6){ mysql_fetch_assoc returns an associative array. In your if statement you're trying to compare an array ($monthsoldrow) to a number. You'll want to the above lines to be the following: $row = mysql_fetch_assoc($GetDate); //if its been 6 months echo the secret button If ($row['MonthsOld'] > 6){ If it still does work as expected use print_r to display the contents of the $row array. Quote Link to comment https://forums.phpfreaks.com/topic/75013-6-months-old/#findComment-379365 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.