Jump to content

how many days from register


Recommended Posts

iIT5Mb3.png

 

I wrote some code to show how many days have passed since user register on Truckersmp.

But it's display two results, second is okay but why it show the first one?

Somebody can help me? I'm trust that its easy to fix that :)

 

Thanks for help

 

<?php
include("connect.php");
$query = mysql_query("SELECT truckersmp_id FROM users WHERE id='".$_SESSION['id']."'"); // 1
while($rekord = mysql_fetch_array($query))
{
$json_string = 'http://api.truckersmp.com/v2/player/'.$rekord[0].'';
$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata);
foreach($obj as $value){
$myJSON = $value->joinDate;
$cdate = strtotime($myJSON);
$today = time();
$difference = $today - $cdate;
echo "". floor($difference/60/60/24)." days";
}
}
?>

 

sygnatura.php?nick=PolishBandit%20(ID:%2

Link to comment
Share on other sites

21 hours ago, RayRay5 said:

how many users / ids are stored in your database? It looks like there are two entries with the same id

About 30 users in my database.

IDs are unique, every person has other ID number in table.

20 hours ago, Kid Fabi said:

Little tip:

You should use "mysqli" instead of "mysql". Mysql is too old. Read about it in internet ;)

 

KinD Regards 

I know man that i should use mysqli or PDO but i learned on mysql and i will must to learn more about it. At this time for my company its working. Im gonna rewrite all code to mysqli in future.

20 hours ago, _J-M said:

Your code isn't secure. Use MySQLi with Prepare Statement

Like you can see in this example:
https://github.com/jean8mathieu/UrlShortner/blob/master/API.php#L62

 

I didn't learn mysqli, i need to do that asap. Can you rewrite my code if its not a problem, please? :) Thanks 

sygnatura.php?nick=PolishBandit%20(ID:%2

Link to comment
Share on other sites

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