Hello,
I've done all functions in my program, except for one:
I want my members to see how many days they have left to use my program features.
I think i need to set upgrade finish time and insert into MySQL db. Then every time user logs in, time between now and upgrade end is calculated and displayed to the member.
Now what I want to know is how to set destination time and how to calculate how much time has been left till end. I want to display only days and set time only with year, month and day. So hours, seconds and minutes won't be needed.
Thanks for any suggestions.
how many days left
Moderator: General Moderators
recent versions of mysql support the function date_diff, see http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
Problems comming 
when calculating the time between two dates and echo'ing it, only "recource id #7" comes out and no result of calculation. Here's the code I wrote:
when calculating the time between two dates and echo'ing it, only "recource id #7" comes out and no result of calculation. Here's the code I wrote:
Code: Select all
function daysleft($userid){
$sql = "SELECT * FROM users WHERE id='$userid'";
$res = mysql_fetch_array(mysql_query($sql));
$date = $res['upgrade'];
$sql = "SELECT DATEDIFF('$date', NOW())";
$result = mysql_query($sql);
return $result;
}
echo daysleft(1);Solved. Man, i have to ask less and search more 
To those who is interested in answer:
To those who is interested in answer:
Code: Select all
function daysleft($userid){
$sql = "SELECT * FROM users WHERE id='$userid'";
$res = mysql_fetch_array(mysql_query($sql));
$date = $res['upgrade'];
$sql = "SELECT DATEDIFF('$date', NOW())";
$result = mysql_query($sql);
$res = mysql_result($result, 0); // use this to fetch first row(0) of a result($result)
return $res;
}
echo daysleft(1);Why do you fetch the stored date only to use it in another query?
Code: Select all
function daysleft($userid){
$sql = "SELECT DATEDIFF(upgrade, NOW()) FROM users WHERE id='$userid'";
$result = mysql_query($sql) or die(mysql_error();
return mysql_result($result, 0);
}