Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 显示错误总pop的sql查询_Php_Mysql_Sql - Fatal编程技术网

Php 显示错误总pop的sql查询

Php 显示错误总pop的sql查询,php,mysql,sql,Php,Mysql,Sql,我对我的sql查询有一些问题,该查询用于获取一个玩家结合所有城镇的总pop,但由于某些原因,它给出了错误的总pop 我还被告知使用绑定参数,但我不确定它们是什么以及如何使用它们。任何帮助都很好,谢谢你 <!DOCTYPE html> <html> <head> <style> table { width: 100%; border-collapse: collapse; } table, td, th { border:

我对我的sql查询有一些问题,该查询用于获取一个玩家结合所有城镇的总pop,但由于某些原因,它给出了错误的总pop 我还被告知使用绑定参数,但我不确定它们是什么以及如何使用它们。任何帮助都很好,谢谢你

<!DOCTYPE html>
<html>
<head>
<style>
table {
    width: 100%;
    border-collapse: collapse;
}

table, td, th {
    border: 1px solid black;
    padding: 5px;
}

th {text-align: left;}
</style>
</head>
<body>

<?php
$q = intval($_GET['q']);
$latitude = -838;
$longitude = -493;
$con = mysqli_connect('localhost','User','Password','Database');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"Database");
$sql="SELECT towns.location_x,  towns.location_y,  players.*, 
            town_deltas.*, town_deltas.town_id, 
            sum( town_deltas.population ) as total_population  
      FROM `town_deltas` 
        LEFT JOIN players ON town_deltas.owner_id = players.player_id 
        LEFT JOIN towns ON town_deltas.town_id = towns.town_id 
      WHERE town_deltas.owner_id = '".$q."' 
      GROUP BY owner_id, data_timestamp 
      ORDER BY `town_deltas`.`town_id` ASC, 
               `town_deltas`.`data_timestamp` ASC";



$result = mysqli_query($con,$sql); 
echo "<table>
<tr>

<th>data_timestamp</th>

<th>name</th>


<td>population</td>
<td>location_x</td>
<td>location_y</td>
<td>distance</td>
</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";


    echo "<td>" . $row['data_timestamp'] . "</td>";

    echo "<td>" . $row['Player_name'] . "</td>";


    echo "<td>" . $row['total_population'] . "</td>";

    echo "<td>" . $row['location_x'] . "</td>";
    echo "<td>" . $row['location_y'] . "</td>";
    echo "<td>" . $row['distance'] . "</td>";

    echo "</tr>";
}

echo "</table>";
mysqli_close($con);
?>
</body>
</html>
你应该展示什么

牌桌

城镇三角洲表


城镇人口将一次又一次地重复出现。你不想要总数。就拿max来说吧:


您的查询还存在许多其他问题,尤其是SELECT中的列没有正确聚合。不过,这可能会解决您眼前的问题。

城镇人口将反复出现。你不想要总数。就拿max来说吧:


您的查询还存在许多其他问题,尤其是SELECT中的列没有正确聚合。但是,这可能会解决您当前的问题。

我删除了sql server标记。您有足够的代表,应该知道如何使用正确的数据库标记问题。而且,如果您想要三列数据,即时间戳、名称、人口,那么为什么要选择无数其他列?您的脚本甚至可能会看到使用oops sry时发生了什么。我发布了一个问题已经有一段时间了,我只是点击了标签上显示的东西。位置x和位置Y是不需要的,它们是我用于sql查询的代码遗留下来的,用于获取a玩家拥有的每个城镇的列表。需要Player和town_delta来获取播放器的名称以及其他代码位所需的数据。在阅读准备好的语句和绑定参数stbh@riggsfully时,我希望看到一个sql注入通过intval在本例中Lol。。。不过,不要说你对准备好的语句错了,应该始终使用它们:DI删除了sql server标记。您有足够的代表,应该知道如何使用正确的数据库标记问题。而且,如果您想要三列数据,即时间戳、名称、人口,那么为什么要选择无数其他列?您的脚本甚至可能会看到使用oops sry时发生了什么。我发布了一个问题已经有一段时间了,我只是点击了标签上显示的东西。位置x和位置Y是不需要的,它们是我用于sql查询的代码遗留下来的,用于获取a玩家拥有的每个城镇的列表。需要Player和town_delta来获取播放器的名称以及其他代码位所需的数据。在阅读准备好的语句和绑定参数stbh@riggsfully时,我希望看到一个sql注入通过intval在本例中Lol。。。不过,不要说你对准备好的陈述是错的,你应该始终使用它们:D
data_timestamp      name         population
2016-09-25 00:03:29 Kodabear    50315100
data_timestamp       name    population
2016-09-25 00:03:29 Kodabear  335,434
player_id   race_id alliance_id alliance_role_id    Player_name 
237186        1     78           381                 Kodabear
5198444 2016-09-21 00:03:47 282609  237186  01 Smokey The Bear  29634   0 0
5198445 2016-09-21 00:03:47 289820  237186  02 Littlebears  28557   0   0   
5198446 2016-09-21 00:03:47 292694  237186  03 Panda-bear   28068   0   0
5198447 2016-09-21 00:03:47 296040  237186  04 Humphrey 29420   1   1
5198448 2016-09-21 00:03:47 296593  237186  05 Winnie-the-Pooh  29527   0   0
5198449 2016-09-21 00:03:47 296914  237186  06 Shayna The Bear  29287   0   0
5198450 2016-09-21 00:03:47 301887  237186  07 Basil the Bear   27684   0   0
5198451 2016-09-21 00:03:47 316315  237186  08 Gummybear    27546   0   0
5198452 2016-09-21 00:03:47 350576  237186  09 Paddington   28919   0   0
5198453 2016-09-21 00:03:47 365385  237186  10 Walkingbear  26369   0   0
5198454 2016-09-21 00:03:47 377604  237186  11 Panserbjørne    25636   0   0
5198455 2016-09-21 00:03:47 404089  237186  12 YogiBear 19672   0   0
5198456 2016-09-21 00:03:47 405583  237186  13 Baloo    3938    0   0
SELECT towns.location_x,  towns.location_y,  players.*, 
       town_deltas.*, town_deltas.town_id, 
       max( town_deltas.population ) as total_population