我有问题让这个工作。我想从数据库中选择行并将其呈现为列表。这是我的代码:
<ul class = "list">
<li>
<?php
$x = 'some_string';
$title = 'title';
$dbc = mysqli_connect('localhost', 'root', '', 'database') or die('Error connecting');
$query = "SELECT * FROM table WHERE column ==$x ORDER BY procenat DESC LIMIT 5";
$data = mysqli_query($dbc, $query);
?>
<div id = "listdiv">
<?php
while ($row = mysqli_fetch_array($data)) {
?>
<h4><?php echo $row[$title]; ?> </h4>
<?php
}
mysqli_close($dbc);
?>
</div> </li> </ul>
我尝试使用LIKE'%$ x%'并且效果不佳。我试过...... column = $ x
答案 0 :(得分:0)
您需要使用单个等号和引号。
$query = "SELECT * FROM table WHERE column = '$x' ORDER BY procenat DESC LIMIT 5";
答案 1 :(得分:0)
您应该像这样使用LIKE运算符
$query = "SELECT * FROM table WHERE column_name LIKE '%$x%' ORDER BY procenat DESC LIMIT 5
答案 2 :(得分:0)
更改查询行,如下所示
$query = "SELECT * FROM table WHERE column = '".$x."' ORDER BY procenat DESC LIMIT 5";
答案 3 :(得分:0)
您的查询中有两个错误只是尝试这个。
$x
替换为'$x'
==
替换为=
$x = 'some_string'; $query = "SELECT * FROM table WHERE column ='$x' ORDER BY procenat DESC LIMIT 5";