Jump to content

Trying to minus all rows in 1 colum


brucegre94

Recommended Posts

If you're doing what I think you're doing, you should set the expiry date to be today's date + 30 days.  Then the account is expired when the current date is after the expiry date.

 

So date("m/d/y") + 30 ?

 

 

There is an easier way. When creating/updating the user's record to set their expiration date you could use something like the following

UPDATE users SET expiration = DATE_ADD(NOW(), INTERVAL 30 DAY) WHERE user_id = $user_id

 

Now there is no need to update the expiration value each day for all users. When the user accesses the site, determine if the expiration date is after the current date. If so, the user is a premium member. If not, they are a standard member.

Link to comment
Share on other sites

If you're doing what I think you're doing, you should set the expiry date to be today's date + 30 days.  Then the account is expired when the current date is after the expiry date.

 

So date("m/d/y") + 30 ?

 

 

 

There is an easier way. When creating/updating the user's record to set their expiration date you could use something like the following

UPDATE users SET expiration = DATE_ADD(NOW(), INTERVAL 30 DAY) WHERE user_id = $user_id

 

Now there is no need to update the expiration value each day for all users. When the user accesses the site, determine if the expiration date is after the current date. If so, the user is a premium member. If not, they are a standard member.

 

so

<?
$con = mysql_connect("$host","$username","$password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$db_name", $con);



$result = mysql_query("SELECT * FROM $tbl_name
WHERE myusername='$myusername'");

while($row = mysql_fetch_array($result))
  {
  $premium = $row['premium'];
  echo "";
  }
if ($premium < date(m/d/y){
  echo  'Standard <a href="upgrade.php">'; echo 'Upgrade'; echo '</a>'; echo '</td>';
   } elseif ($premium > date(m/d/y) {
  echo  'Premium'; echo '</td>';
   } else {
   }

mysql_close($con);
?>   

 

I have been teaching myself php and this is fustrating me.

Link to comment
Share on other sites

More like this

$query = "SELECT IF(`premium`>=NOW(), 1, 0) as premium
          FROM $tbl_name
          WHERE myusername='$myusername'";
$result = mysql_query($query);

$row = mysql_fetch_array($result);

if (!$row['premium'])
{
    echo  'Standard <a href="upgrade.php">'; echo 'Upgrade'; echo '</a>'; echo '</td>';
}
else ($premium > date(m/d/y)
{
    echo  'Premium'; echo '</td>';
}

Link to comment
Share on other sites

More like this

$query = "SELECT IF(`premium`>=NOW(), 1, 0) as premium
          FROM $tbl_name
          WHERE myusername='$myusername'";
$result = mysql_query($query);

$row = mysql_fetch_array($result);

if (!$row['premium'])
{
    echo  'Standard <a href="upgrade.php">'; echo 'Upgrade'; echo '</a>'; echo '</td>';
}
else ($premium > date(m/d/y)
{
    echo  'Premium'; echo '</td>';
}

Thank you so much. Could you tell me how I would update my database. After they pay me I check the IPN via paypal and send them to a page that changes the value of the experiation date, but I cannot make it add 30 days to the date.

Link to comment
Share on other sites

Could you tell me how I would update my database. After they pay me I check the IPN via paypal and send them to a page that changes the value of the experiation date, but I cannot make it add 30 days to the date.

 

I already gave you an example of the UPDATE query in my first response.

Link to comment
Share on other sites

Could you tell me how I would update my database. After they pay me I check the IPN via paypal and send them to a page that changes the value of the experiation date, but I cannot make it add 30 days to the date.

 

I already gave you an example of the UPDATE query in my first response.

 

It doesn't add a date. It adds DATE_ADD(NOW(), INTERVAL 30 DAY) to the database.

Link to comment
Share on other sites

  • 4 weeks later...
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.