0

I am trying to create a Wordpress webpage that has an input text box and a button. what I want to do is take the input text from the text box and use it as a parameter to search a table I put into the website database and print the results on the screen. I tried using PHP to no avail. what is the best to do this? here is the code Search the Film Database [php] global $wpdb; echo 'Search'; $text = sanitize_text_field($_POST['input']); echo $text; $wpdb->query('USE vcuw2938212664'); function myFunction(){ $txt = sanitize_text_field($_POST['input']); echo 'text is "$txt; $query = 'SELECT * FROM documentaries WHERE English_Title = \'%Li%\';'; echo $query; $results = $wpdb->get_results($query); if ($results != Null){ echo "{$results}"; } else { echo 'no results returned'; } } [/php]

  • 1
    Can you show what you have tried in your question please? – Nathan Powell Oct 27 '16 at 22:58
  • sure! here is my code! – user3533573 Nov 4 '16 at 13:56
  • Search the Film Database <input id="input" name="input" type="text" /> [php] global $wpdb; echo '<button type="button" onclick="myFunction()">Search</button>'; $text = sanitize_text_field($_POST['input']); echo $text; $wpdb->query('USE vcuw2938212664'); function myFunction(){ $txt = sanitize_text_field($_POST['input']); echo 'text is "$txt; $query = 'SELECT * FROM documentaries WHERE English_Title = \'%Li%\';'; echo $query; $results = $wpdb->get_results($query); if ($results != Null){ echo "{$results}"; } else { echo 'no results returned'; } } [/php] – user3533573 Nov 4 '16 at 13:57
  • Please put the code in your question and format it. – Nathan Powell Nov 4 '16 at 14:17
0

you can use WP_Query(); to query the results.

it has an argument 's' => $search_query,

create an input, get the input value, store it in $search_query, then create a query,

$query = new WP_Query( array( 'post_type' => 'post', 's' => $search_query ) );
if ( $query->have_posts() ) : 
     while ( $query->have_posts() ) : $query->the_post();

     // do something...

     endwhile;
     wp_reset_query();
endif;
  • i use ajax to create custom search forms for advance property search you can see an example here : 216.120.250.9/~kathleenkellett/local-info/businesses – Aamer Shahzad Nov 8 '16 at 16:19
  • I know that I want to search a table named "documentaries" that I already inputted and and to find row where the the column "English_Title" has the input String in it. How do I do that? – user3533573 Nov 8 '16 at 18:48
  • by the way, I am having a problem looking for a way to get a button to run it! – user3533573 Nov 8 '16 at 19:13
  • the table name is "documentaries" ? what are you creating? – Aamer Shahzad Nov 8 '16 at 22:33
  • I am creating a database SQL search engine to search the table "documentaries" based on a user inputted string from the input called "input" and prints the results of that search to the screen – user3533573 Nov 15 '16 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.