Ch4ch4rR4t0
Active Member
- Aug 19, 2016
- 77
- 7
- 83
what, no is possible, is connection same varIm gonna look it when i will be home.
$get_user = $connect->query("SELECT * FROM users WHERE username= '$_SESSION['username']'");
$get_user = $connect->query("SELECT * FROM users WHERE username= '{$_SESSION['username']}'");
$get_user = $connect->query("SELECT * FROM users WHERE username= '" . $_SESSION['username'] . "'");
No working!!!you can't use vairables in single qoutes, replace
PHP:get_time_ago('$GetDataLog');
with
PHP:get_time_ago($GetDataLog);
public static function historyPurchases()
{
global $connect;
$user = $_SESSION['username'];
$get_history = $connect->query("SELECT id,user,product_name,product_id,price,Status, Buyed FROM purchases WHERE user = '$user' ORDER BY id");
$row_this = $get_history->num_rows;
if($row_this)
{
while($history_fetch = $get_history->fetch_array(MYSQLI_ASSOC))
{
if($history_fetch['Status'] == 3){
$msgStatus = "<font color=green>Approved</font>";
}else if($history_fetch['Status'] == 2){
$msgStatus = "<font color=red>Failed</font>";
}else if($history_fetch['Status'] == 4){
$msgStatus = "<font color=warning>Refunded</font>";
}else if($history_fetch['Status'] == 5){
$msgStatus = "<font color=orange>Locked</font>";
}else{
$msgStatus = "<font color=red>Error</font>";
}
$adata = new DateTime($history_fetch['Buyed']);
$GetDataLog = $adata->format("d/M/Y H:i:s");
$GetDataAgo = get_time_ago($GetDataLog);
echo '
<tr>
<td>'.$history_fetch['product_id'].'</td>
<td>'.$history_fetch['product_name'].'</td>
<td>$'.$history_fetch['price'].'</td>
<td>'.$msgStatus.'</td>
<td>'.$GetDataLog.'</td>
<td>'.$GetDataAgo.' (beta)</td>
</tr>';
}
}
}
$GetDataAgo = get_time_ago($GetDataLog);
$timestamp = strtotime($adata->format("d.m.Y H:i:s"));
$GetDataAgo = get_time_ago($timestamp);
i'm assuming you are using the get_time_ago function from w3schools.in (http://www.w3schools.in/php/time-ago/) You need to convert your formatted time into a timestamp and it should work.
replace
PHP:$GetDataAgo = get_time_ago($GetDataLog);
with
PHP:$timestamp = strtotime($adata->format("d.m.Y H:i:s")); $GetDataAgo = get_time_ago($timestamp);
And i hope you know what you are doing, i see a lot of potential XSS vulnerabilities in your code...
$GetDataLogAgo = $adata->format("d/m/Y H:i:s");
$GetDataAgo = get_time_ago($GetDataLogAgo);
function get_time_ago($timestamp)
{
$time_ago = strtotime($timestamp);
$current_time = time();
$time_difference = $current_time - $time_ago;
$seconds = $time_difference;
$minutes = round($seconds / 60 ); // value 60 is seconds
$hours = round($seconds / 3600); //value 3600 is 60 minutes * 60 sec
$days = round($seconds / 86400); //86400 = 24 * 60 * 60;
$weeks = round($seconds / 604800); // 7*24*60*60;
$months = round($seconds / 2629440); //((365+365+365+365+366)/5/12)*24*60*60
$years = round($seconds / 31553280); //(365+365+365+365+366)/5 * 24 * 60 * 60
if($seconds <= 60)
{
return "Just Now";
}
else if($minutes <=60)
{
if($minutes==1)
{
return "one minute ago";
}
else
{
return "$minutes minutes ago";
}
}
else if($hours <=24)
{
if($hours==1)
{
return "an hour ago";
}
else
{
return "$hours hrs ago";
}
}
else if($days <= 7)
{
if($days==1)
{
return "yesterday";
}
else
{
return "$days days ago";
}
}
else if($weeks <= 4.3) //4.3 == 52/12
{
if($weeks==1)
{
return "a week ago";
}
else
{
return "$weeks weeks ago";
}
}
else if($months <=12)
{
if($months==1)
{
return "a month ago";
}
else
{
return "$months months ago";
}
}
else
{
if($years==1)
{
return "one year ago";
}
else
{
return "$years years ago";
}
}
}
$GetDataAgo = get_time_ago($GetDataLog);
$GetDataAgo = get_time_ago($history_fetch['Buyed']);