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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.