如何在管理页面中向表格结果添加搜索框

时间:2019-03-01 作者:Schmutly

我有一个自定义数据库,我成功地将其带到我的插件子菜单页面,它显示了非常好的结果。如果使用phpmyadmin手动向DB添加一行,则刷新时会显示该结果。这里是该数据库结果页的屏幕截图:->http://prntscr.com/mropc3 代码如下:

<table border="1">
 <tr>
  <th>First Name</th> 
  <th>Last Name</th> 
  <th>Buyer\'s Email Address</th>
  <th>Software Title</th> 
  <th>IP Address 01</th> 
  <th>IP Address 02</th>
  <th>Payment Status</th>
 </tr>
 <?php
        global $wpdb;
        $ipn_tables = $wpdb->prefix ."ipn_data_tbl";

        $result = $wpdb->get_results ( "SELECT * FROM $ipn_tables" );
        foreach ( $result as $print )   {
        ?>
           <tr>     
           <td><?php echo $print->first_name;?></td>
           <td><?php echo $print->last_name;?></td>
           <td><?php echo $print->payer_email;?></td>
           <td><?php echo $print->item_name;?></td>
           <td><?php echo $print->ip_address_01;?></td>
           <td><?php echo $print->ip_address_02;?></td>
           <td><?php echo $print->payment_status;?></td>
    </tr>
        <?php }
  ?></table>
我预先添加了一个搜索框,但介绍了如何搜索此html表并显示搜索结果。已经查找了一整天,并尝试在两个不同的函数中重复上述代码两次,然后尝试以下操作:

<form>
    <form method="post" action="" >
    <input type="text" placeholder="Search Transactions.." name="submit">
    <input type="submit" class="button-primary" value="Search" name="submit">
    <input type="reset" class="button-primary" value="Reset Form">
</form>


<?php

if(isset($_POST[\'submit\']) && !empty($_POST[\'submit\'])) {
  // there is something in the field, do stuff
  $search = $_POST["search"];
  return_esb_searches ();
  echo "searching";
} else {
  // trigger normal results
  all_esb_results ();
 echo "showing normal results display without search";
}
在“搜索”功能中,我尝试了:

 $result = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$ipn_tables} WHERE item_name like $search OR first_name like $search OR last_name like $search OR payer_email like $search" ));
任何帮助都将不胜感激。

1 个回复
最合适的回答,由SO网友:Qaisar Feroz 整理而成

<form>
<form method="post" action="" >
<input type="text" placeholder="Search Transactions.." name="submit">
<input type="submit" class="button-primary" value="Search" name="submit">
<input type="reset" class="button-primary" value="Reset Form">
</form>
应该是

<form method="post" action="" >
    <input type="text" placeholder="Search Transactions.." name="search">
   <input type="submit" class="button-primary" value="Search" name="submit">
   <input type="reset" class="button-primary" value="Reset Form">
</form>
即删除额外的开始标签<form> 和用于文本字段name="submit" 应该是name="search"

我希望这能奏效!

相关推荐

必需:在文件search.php中找到Get_BloInfo(‘模板_url’)。改用GET_TEMPLATE_DIRECTORY_URI

主题检查错误→REQUIRED: get_bloginfo(\'template_url\') was found in the file search.php. Use get_template_directory_uri() instead. Line 21: <img src=\'<?php echo get_bloginfo(\'template_url\') ?>/img/no_results_found.png\'/> 我采取了行动并进行了更改,但该图