dongyong2906 2013-11-13 23:42
浏览 17
已采纳

在PHP中从数据库获取数据时出错

I'm new at PHP, and trying to set up a simple test to get data to return from a temp database I set up, but I keep getting a syntax error. I've looked it over and after the process of elimination, it seems to be in this line, but I'm not sure what's wrong since I'm pretty sure it looks just like the tutorial I'm using.

    while($row = mysqli_fetch_row($result)) {

Here is the all the code relevant to what I'm doing:

    <?php
// Perform database query
$query = "SELECT * FROM subjects";
$result = mysqli_query($connection, $query);

// Test if there was a query error
if (!$result) {
    die ("Database query failed.");
}
    ?>

    <?php
// Use returned data (if any)
while($row = mysqli_fetch_row($result)) {
    // output data from each row
    var_dump($row);
    echo "<hr />";
    ?>

I'm able to successfully make the initial connection, etc, it's just when I tried to get data to show up from the database that I got the syntax error.

  • 写回答

1条回答 默认 最新

  • dounei5721 2013-11-13 23:45
    关注

    It's here, you missed your closing braces

    <?php
      //Use returned data (if any)
      while($row = mysqli_fetch_row($result)) {
       // output data from each row
       var_dump($row);
       echo "<hr />";
      } //you missed your closing braces
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示