PHP没有打印任何东西

PHP没有打印任何东西

问题描述:

I have a html file with php in it that is suppose to be querying a MYSQL database for information about the top 25 players with their kills deaths etc. However the page keeps loading blank and I cannot work out what is wrong. The database does have plenty of entries into it. The server hosting this file also does have PHP installed. Could someone please show me where the issue is or tell me what could be causing this issue? Cheers Code:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<?php
   require_once( "connect.php" );

   $select_top_25 = "
      SELECT     `stats_players`.`name`,
                 `stats_total_pvp_kills`.`times`, 
                 `stats_total_deaths`.`times` 
      FROM       `stats_players`
      INNER JOIN `stats_total_pvp_kills`
      BY         `stats_players`.`player_id` = `stats_total_pvp_kills`.`player_id`
      INNER JOIN `stats_total_deaths`
      BY         `stats_players`.`player_id` = `stats_total_deaths`.`player_id`
      ORDER BY   `stats_total_pvp_kills`.`times` ASC LIMIT 25";

   $result = mysqli_query($link, $select_top_25) or die (mysqli_error($link));

   $counter = 0;
   while($row = mysqli_fetch_row($result))
   {

       $counter = $counter + 1;
       print '#'.$counter;
       print 'Name: '.$row[0];
       print 'Kills: '.$row[1];
       print 'Deaths: '.$row[2];

   }
?>
</body>
</html>

Try to replace BY with ON like this:

SELECT     `stats_players`.`name`, 
           `stats_total_pvp_kills`.`times`, 
           `stats_total_deaths`.`times` 
FROM       `stats_players`
INNER JOIN `stats_total_pvp_kills`
ON         `stats_players`.`player_id` = `stats_total_pvp_kills`.`player_id`
INNER JOIN `stats_total_deaths`
ON         `stats_players`.`player_id` = `stats_total_deaths`.`player_id`
ORDER BY   `stats_total_pvp_kills`.`times` ASC LIMIT 25

This could help.

Generally for such case, when you are not sure whats the actual error you should debug script step by step and at there the first thing here you need to check is, echoing any simple text before doing any mySql stuff.

Means before including connect.php you should do echo 'hii'; exit; and run it. if its display correctly then you can move ahead to check on my sql query and result

Possible cases here for an issue are

  1. You have saved file with html extension and not with PHP extension
  2. There is no result coming with you mysql query because of any reason

Possible reasons for this:

  • Your file is a .html and not a .php file
  • You dont have a apache running (if its local)
  • You dont have it in the right directory (if its local and apache is running)
  • Soemthing is wrong with the fileinclude (connect.php)
  • No DB connection
  • Variable $link is not set
  • Your mysql syntax is wrong ( its INNER JOIN ... ON ... not BY )
  • Your mysql has no result
  • No errors are showing up because of php.ini setup