Jump to content

6 months old


SirChick

Recommended Posts

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">
';
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/75013-6-months-old/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/75013-6-months-old/#findComment-379365
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.