dsa45132 2014-04-09 15:55
浏览 10
已采纳

PHP - SQL选择数据显示

<html>
<head>
    <meta http-equiv = "content-type" content = "text/html; charset = utf-8" />
    <title>Using file functions PHP</title>
</head>
<body>
<h1>Web Development - Lab05</h1>
<?php
   require_once("settings.php");
   $dbconnect = @mysqli_connect($host, $user, $pswd, $dbnm);
    if($dbconnect->connect_errno >0)
    {
        die('Unable to connecto to database [' . $db->connect_error . ']');
    }

    $queryResult = "SELECT car_id, make, model, price FROM cars";

    echo "<table width='100%' border='1'>";
    echo "<tr><th>ID</th><th>Make</th><th>Model</th><th>Price</th></tr>";

    //initiate array 
    $displayrow= mysqli_fetch_array($queryResult);

    //initiate while loop to iterate through table
    while($displayrow)
    {
        echo "<tr>";
        echo "<td>" . $row['ID'] . "</td>";
        echo "<td>" . $row['Make'] . "</td>";
        echo "<td>" . $row['Model'] . "</td>";
        echo "<td>" . $row['Price'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
    mysqli_close($dbconnect);
?>
</body>
</html>

This is doing my head in, I cannot figure out why it will not display the actual data apart from the Table header. No matter what I used. I have tried mysqli_fetch_array, mysqli_fetch_row, mysqli_fetch_assoc but nothing works.

Help and explanation why it was not displaying the data would be much appreciated :)

  • 写回答

5条回答 默认 最新

  • douyiji3919 2014-04-09 16:13
    关注

    Please Precision to names of field in Query ( car_id,make,...)

    while($displayrow= mysql_fetch_assoc($queryResult) )
    {
    echo "<tr>";
        echo "<td>" . $displayrow['car_id'] . "</td>";
        echo "<td>" . $displayrow['make'] . "</td>";
        echo "<td>" . $displayrow['model'] . "</td>";
        echo "<td>" . $displayrow['price'] . "</td>";
        echo "</tr>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化