alfawolf Posted July 31, 2015 Share Posted July 31, 2015 I'm trying to fetch some value's from a database. The database contains 2 tables, when i try to join the data i get nothing, no output on screen , no text on screen. when i do the query for each, it works. now i tried several examples but nothing works....i just don't get it !? This is the code: <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><table width="600" height="100" border="1"> <tr style="color:#00CC00"> <th width="50"></th> <th width="200">Player Name:</th> <th width="50">Player Online:</th> <th width="100">EXP Total</th> <th width="300">Player Playtime:</th> </tr> <?php$servername = "";$username = "";$password = "";$dbname = "";$port = "";// Create connection$conn = new mysqli($servername, $username, $password, $dbname, $port);// Check connectionif ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);} $sql = "SELECT a.player_id, a.online, a.playtime, a.name, b.exp_total"; "FROM stats_players a, stats_misc_info_players b"; "where a.player_id=b.exp_total"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { ?> <tr style="color:#CCCCCC"> <td width="50"><?php echo $row["player_id"];?></td> <td width="200"><?php echo $row["name"];?></td> <td width="50"><?php echo $row["online"];?></td> <td width="100"><?php echo $row["exp_total"];?></td> <td width="300"><?php echo $row["playtime"];}} $conn->close() ?></td> </tr></table></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/297571-simple-mysql-query/ Share on other sites More sharing options...
maxxd Posted July 31, 2015 Share Posted July 31, 2015 You're ending your query string 3 different times. Try $sql = " SELECT a.player_id, a.online, a.playtime, a.name, b.exp_total FROM stats_players a, stats_misc_info_players b where a.player_id=b.exp_total "; Also, add ini_set('display_errors',true); error_reporting(-1); at the top of your script. Blank white pages mean there's an error in the code, and the above lines will force those errors to display. Quote Link to comment https://forums.phpfreaks.com/topic/297571-simple-mysql-query/#findComment-1517829 Share on other sites More sharing options...
Barand Posted July 31, 2015 Share Posted July 31, 2015 SELECT a.player_id, a.online, a.playtime, a.name, b.exp_total FROM stats_players a, stats_misc_info_players b where a.player_id=b.exp_total Are sure you really want to match on a.player_id=b.exp_total? Seems strange to match an id against a total, or just bad column naming. If that is the case, why bother to select both columns if you know they are going to be the same in the results Quote Link to comment https://forums.phpfreaks.com/topic/297571-simple-mysql-query/#findComment-1517832 Share on other sites More sharing options...
alfawolf Posted July 31, 2015 Author Share Posted July 31, 2015 Maxxd thanks.....and Barand i'm a noob with myqsl and php Quote Link to comment https://forums.phpfreaks.com/topic/297571-simple-mysql-query/#findComment-1517843 Share on other sites More sharing options...
alfawolf Posted August 1, 2015 Author Share Posted August 1, 2015 Barand, you had a point there, changed it, cleaner, thanks Quote Link to comment https://forums.phpfreaks.com/topic/297571-simple-mysql-query/#findComment-1517845 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.