dongshuang0011 2018-06-11 07:35
浏览 53
已采纳

在sql中使用COUNT时。 我得到错误未定义的索引

I am trying to make tables that display data on my web page but every timeI use the count function in my sql query I get the error Undefined index on line 19.

Position in/Library/WebServer/Documents/students/steve/Sites/tables.php on line 19

The php code looks like this.

<?php
include('db-connect.php');
include('top.php');

$query = 'SELECT   Nationality, COUNT(Position)
          FROM     2017_Crankworx_Results
          WHERE    Position = 1
          GROUP BY Nationality
          ORDER BY Nationality ASC';
$results = mysqli_query($link, $query) or die(mysqli_error($link));

echo '<table>';
echo '<th>Nationality</th>';
echo '<th>Position</th>';
echo '<br><br>';

while($crank = mysqli_fetch_assoc($results))
{
    echo '<tr>';
    echo '<td>'.$crank['Nationality'].'</td>';
    echo '<td>'.$crank['Position'].'</td>';
    echo '</tr>';
}

echo '</table>';

include('bottom.php');
mysqli_close($link);
?>

I you could tell me if there is something that not right with my code or if I am doing something else worng that would be great.

  • 写回答

3条回答 默认 最新

  • donglang1894 2018-06-11 07:40
    关注

    add " as Position" after "COUNT(Position)" in your SQL, or replace the index "Position" to "COUNT(Position)" at referencing the array

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率