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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题