我发现很难在wordpress中使用php pdo分页返回数据库结果。我在另一个页面上有一个表单,它将搜索数据发送到search4.php,我想显示匹配的行并有前一个|下一个链接。我没有得到任何结果,如果我回复$ search,它只是说'搜索' 以下是目前的相关代码:
//html form on another page
<form method="POST" action="<?www.example.com/search4 ?>">
Search:
<input type="text" name="search"
<input type="submit" name="search" value="search" /></form>
//search4.php relevant code
if(isset($_REQUEST["search"]) && $_REQUEST["search"] != "")
{
$search = htmlspecialchars($_REQUEST["search"]);
$pagination->param = "&search=$search";
echo $search;
$pagination->rowCount("SELECT * FROM stories WHERE stories.category LIKE
'%$search%' OR stories.genre = LIKE '%$search%'");
$pagination->config(3, 8);
$sql = "SELECT * FROM stories WHERE stories.category LIKE '%$search%' OR
stories.genre = LIKE '%$search%' ORDER BY SID ASC LIMIT $pagination-
>start_row, $pagination->max_rows";
$query = $connection->prepare($sql);
$query->execute();
$model = array();
while($rows = $query->fetch())
{
...etc
答案 0 :(得分:0)
您<input type=text>
和您的<input type=submit>
具有相同的名称...因此,按钮值会覆盖您的文字值...为什么始终是“搜索”。
将其更改为:
<input type="text" name="search_text"/>
<input type="submit" name="search_button" value="search" />
现在,在您的search4.php上,您可以使用$_REQUEST["search_text"]
PD:您也可以删除提交按钮上的name属性。