[GTW] PolishBandit Posted February 20, 2018 Share Posted February 20, 2018 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"; } } ?> Link to comment Share on other sites More sharing options...
RayRay5 Posted February 20, 2018 Share Posted February 20, 2018 how many users / ids are stored in your database? It looks like there are two entries with the same id "Just because others break rules, does not grant you the permission to break the rules as well" Please drive respectful on the servers. Thank you! Link to comment Share on other sites More sharing options...
Web Developer Kid Fabi Posted February 20, 2018 Web Developer Share Posted February 20, 2018 Little tip: You should use "mysqli" instead of "mysql". Mysql is too old. Read about it in internet KinD Regards Link to comment Share on other sites More sharing options...
Web Developer _J-M Posted February 20, 2018 Web Developer Share Posted February 20, 2018 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 1 Link to comment Share on other sites More sharing options...
[GTW] PolishBandit Posted February 21, 2018 Author Share Posted February 21, 2018 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 Link to comment Share on other sites More sharing options...
Recommended Posts