我的搜索不起作用,我不知道为什么。我想在我的数据库中搜索客户或门票。当我在 SEARCH 字段(输入)为空时单击搜索时,我得到所有客户端但是当我在字段中输入一些东西时我什么也得不到。这是代码:
<table class="table table-bordered" id="datatable">
<thead>
<tr>
<th width="6%">name</th>
<th width="6%">prenom</th>
<th width="12%">adresse</th>
<th width="3%">codepost</th>
<th width="6%">ville</th>
<th width="5%">telephone</th>
<th width="8%">email</th>
<th width="6%">type</th>
<th width="5%">Action</th>
</tr>
</thead>
<tbody>
<?php
require 'database.php';
$db = Database::connect();
$statement = $db->query("SELECT * FROM clients WHERE 'prenom' LIKE '%" . $_POST['prenom'] . "%' ORDER BY client_id DESC" );
while($item = $statement->fetch())
{
echo '<tr>';
// echo '<td>'. $item['id'] . '</td>';
echo '<td>'. $item['name'] . '</td>';
echo '<td>'. $item['prenom'] . '</td>';
echo '<td>'. $item['adress'] . '</td>';
echo '<td>'. $item['codepost'] . '</td>';
echo '<td>'. $item['ville'] . '</td>';
echo '<td>'. $item['telephone'] . '</td>';
echo '<td>'. $item['email'] . '</td>';
echo '<td>'. $item['type'] . '</td>';
echo '<td width=150>';
echo '<a class="btn btn-default " href="view.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-eye-open"></span></a>';
echo ' ';
echo '<a class="btn btn-primary" href="update.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-pencil"></span></a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteclient.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-remove"></span> </a>';
echo '</td>';
echo '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
答案 0 :(得分:0)
我最终做到了..感谢谁帮助了我(
Sam Onela)这里是代码,如果有人需要``it:=`
名称
prenom
住址
codepost
威乐
电话
电子邮件
类型
行动
准备(&#34; SELECT * FROM clients WHERE name LIKE?&#34;);
$ req-&gt;执行(数组(&#39;%&#39;。$ searchq。&#39;%&#39;));
$ count = $ req-&gt; rowCount();
echo " $count Résulta(s) trouvé pour <strong >$searchq></strong><hr/> " ;
while($data = $req->fetch()) {
echo '<tr>';
echo '<td>'. $data['name'] . '</td>';
echo '<td>'. $data['prenom'] . '</td>';
echo '<td>'. $data['adress'] . '</td>';
echo '<td>'. $data['codepost'] . '</td>';
echo '<td>'. $data['ville'] . '</td>';
echo '<td>'. $data['telephone'] . '</td>';
echo '<td>'. $data['email'] . '</td>';
echo '<td>'. $data['type'] . '</td>';
echo '<td width=150>';
echo '<a class="btn btn-default " href="view.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-eye-open"></span></a>';
echo ' ';
echo '<a class="btn btn-primary" href="update.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-pencil"></span></a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteclient.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-remove"></span> </a>';
echo '</td>';
echo '</tr>';
}
}
Database::disconnect();
?>
</tbody>
</table>`