最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to add search box to table results in admin page

matteradmin8PV0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I have a custom database that i succesfully brought into my plugin submenu page and it displays the results great. If you manually add a row to the DB with phpmyadmin it shows that result on a refresh. Here's a screen shot of result page from that database here:-> CODE below:

<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>

I pre added a search box but how to search this html table and show results from a search. Have been looking all day and tried the above code repeated twice in two different functions then tried this:

<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";
}

In the 'search' function i tried:

 $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" ));

Any help would be appreciated.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I have a custom database that i succesfully brought into my plugin submenu page and it displays the results great. If you manually add a row to the DB with phpmyadmin it shows that result on a refresh. Here's a screen shot of result page from that database here:-> http://prntscr/mropc3 CODE below:

<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>

I pre added a search box but how to search this html table and show results from a search. Have been looking all day and tried the above code repeated twice in two different functions then tried this:

<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";
}

In the 'search' function i tried:

 $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" ));

Any help would be appreciated.

Share Improve this question edited Mar 1, 2019 at 9:08 Qaisar Feroz 2,1471 gold badge9 silver badges20 bronze badges asked Mar 1, 2019 at 7:17 SchmutlySchmutly 391 gold badge2 silver badges9 bronze badges 1
  • why didn't the code post correctly..? it was meant to look like : prntscr/mroyhy <- this works this is what i tried... but didnt post above correctly prntscr/mroyyq – Schmutly Commented Mar 1, 2019 at 7:32
Add a comment  | 

1 Answer 1

Reset to default 0
<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>

should be

<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>

i.e. Remove extra start tag <form> and for text field name="submit" should be name="search"

I hope this will work!

Post a comment

comment list (0)

  1. No comments so far