我如何从一个带有where子句的表中显示记录?

问题描述 投票:0回答:1
  1. 我想显示一个带有where子句的记录。
  2. 它有一个错误 "试图获取非对象的属性'num_rows'"。

    '<?php'
    'require_once "connect.php";'
    '$sql = "SELECT No,TimeIssued,Type FROM QueueR WHERE Type='Regular'";'
    '$result = $conn->query($sql);' 
    'if($result->num_rows > 0){'
    'echo "<table class='table table-bordered table-striped'>";'
    'echo "<thead>";'
    'echo "<tr>";'
    'echo "<th>No</th>";'
    'echo "<th>TimeIssued</th>";'
    'echo "</tr>";'
    'echo "</thead>";'
    'echo "<tbody>";'
    'while($row = $result->fetch_assoc()){'
    'echo "<tr>";'
    'echo "<td>" . $row['No'] . "</td>";'
    'echo "<td>" . $row['TimeIssued'] . "</td>";'
    'echo "</tr>";'
    '}'
    'echo "</tbody>";'                            
    'echo "</table>";'
    '$result->free();'
    '} else{'
    'echo "<p class='lead'><em>No records were found.</em></p>";'
    '}'
    '?>'
    

    '''

php mysql html-table where-clause record
1个回答
0
投票

检查是否 $conn 中的connect.php连接正常。

试着在mysql客户端测试查询。

使用 include("connect.php") 而不是 require_once "connect.php".

© www.soinside.com 2019 - 2024. All rights reserved.