我有一个自定义数据库,我成功地将其带到我的插件子菜单页面,它显示了非常好的结果。如果使用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" ));
任何帮助都将不胜感激。
最合适的回答,由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"
我希望这能奏效!