jeudi 26 février 2015

Creating a search form and displaying results


Im trying to create a plugin for a site where the user can see a table of orders from customers in the Wordpress dashboard, It's a custom db but I'm using the wp-list-table, I've wrecked my brain for hours trying to get the built in search for that working


I want to create a search form where the user can search this table and return the results in a nice little table for them.


This is my code so far for the search form



<form name="search" method="get">
Order Number: <input type="text" name="find" />
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>



<?php

//This is only displayed if they have submitted the form
if ($searching =="yes") {
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "") {
echo "<p>Please Enter a search term";
exit; }

// filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

global $wpdb;

//Now we search for our search term

$database = $wpdb->get_row("SELECT * FROM storeuserdata2 WHERE orderno = '%$find%'");
//And we display the results
echo "<table>";
echo "<tr>";
echo "<td>".$database->firstname."</td>";
echo "<td>".$database->lastname."</td>";
echo "<td>".$database->email."</td>";
echo "<td>".$database->address."</td>";
echo "<td>".$database->towncity."</td>";
echo "<td>".$database->contactnumber."</td>";
echo "</tr>";
echo "</table>";

echo "<b>Searched For:</b> " .$find;
}


This just hangs on a blank page and shows nothing atm. I want to display the results on the same page on the dashboard


I'm still a complete newb when it comes to php and Wordpress dev, so hopefully im just missing something simple





Aucun commentaire:

Enregistrer un commentaire