dongpu8935 2014-06-26 10:02
浏览 25
已采纳

在php和mysql中链接[重复]

I load data from mysql database and display it into listview jqm. Here is my code:

<?php
       include "connect.php";
        $result = mysqli_query($con,"SELECT * FROM story");
        id==$row['id'];
        echo "<ul data-role='listview' data-inline='true'>";
        while($row = mysqli_fetch_array($result)) {
          echo "<li>" ;
          echo "<a href='view.php?id=".$rows['id']."' data-rel='external'>";
          echo $row['name'];
          echo "</a>";
          echo "</li>";
            }
        echo "</ul>";
        ?>

and view page :

<?php
    include "connect.php";
    $id = $_GET['id'];
    $result = mysqli_query($con,"SELECT * FROM story WHERE id='".$id."'");
    $row = mysqli_fetch_array($result);
    echo $row['content'];

    ?>

But it not working and this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\1\view.php on line 11. What should I do ?

</div>
  • 写回答

2条回答 默认 最新

  • duanfan1869 2014-06-26 10:11
    关注

    This error shows that the SQL Query is unable to get data into $result and if you try to print this result on the screen it will show you bool(false) as output. This parameter when passed into the mysqli_fetch_array() does not fetch array for you because it requires a TRUE boolean value.

    First try to get the data from the database into the $result, print it and then proceed forward.

    Maybe this will help,

    $result = mysqli_query($con,"SELECT * FROM story WHERE id='.$id.' ");

    Remember to always use error checking methods like die, mysqli_error, mysqli_connect_error(), mysqli_connect_errno() etc for better debugging.

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

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line