我对此功能mysqli_num_rows()
有问题,因为有时对我来说效果很好,有时它让我头疼,我真的不知道这是怎么回事
这是我的PHP文件:
<?php
include 'dbh.php';
function get_font_class() {
global $conn;
if ( isset($_POST['dataSearchBox']) ) {
$searchKeyword = $_POST['dataSearchBox'];
$sql = ' SELECT * FROM fontawesomeicons WHERE name LIKE ' .$searchKeyword. '%; ';
$result = mysqli_query($conn, $sql);
if ( mysqli_num_rows( $result ) > 0 ) {
while ( $row = mysqli_fetch_assoc( $result ) ) {
echo '<i class=' .$row['class']. '></i>';
}
} else {
echo "There Are No Icons At The Moment!";
}
}
}
get_font_class();
答案 0 :(得分:0)
在课程属性之前和之后使用双引号
include 'dbh.php';
function get_font_class() {
global $conn;
if ( isset($_POST['dataSearchBox']) ) {
$searchKeyword = $_POST['dataSearchBox'];
$sql = ' SELECT * FROM fontawesomeicons WHERE name LIKE ' .$searchKeyword. '%; ';
$result = mysqli_query($conn, $sql);
if ( mysqli_num_rows( $result ) > 0 ) {
while ( $row = mysqli_fetch_assoc( $result ) ) {
echo '<i class="' .$row['class']. '"></i>';
}
} else {
echo "There Are No Icons At The Moment!";
}
}
}
get_font_class();
答案 1 :(得分:-2)
将sql写为
$sql = "SELECT * FROM fontawesomeicons WHERE name LIKE '%".$searchKeyword."%'" ;