Jump to content

Recommended Posts

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 connection
if ($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>
 

Link to comment
https://forums.phpfreaks.com/topic/297571-simple-mysql-query/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/297571-simple-mysql-query/#findComment-1517829
Share on other sites

 

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

  1. 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.
  2. If that is the case, why bother to select both columns if you know they are going to be the same in the results
Link to comment
https://forums.phpfreaks.com/topic/297571-simple-mysql-query/#findComment-1517832
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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