0

Similar to how you can insert into an array using code such as

$wpdb->insert( $table_name, $inputs); //where inputs is an array

I want to do a sql select statement with code such as

$wpdb->get_results("SELECT * FROM " . $table_name . " WHERE " . $input);

where input could contain several search parameters. Is anything like this possible?

1
  • "Is anything like this possible" won't really bring up the best answers. Better would be to rethink your question and file an edit. Commented Jan 27, 2014 at 17:25

1 Answer 1

0

Pass your information through prepare as in this example from the Codex:

$metakey = "Harriet's Adages";
$metavalue = "WordPress' database interface is like Sunday Morning: Easy.";

$wpdb->query( $wpdb->prepare( 
    "
        INSERT INTO $wpdb->postmeta
        ( post_id, meta_key, meta_value )
        VALUES ( %d, %s, %s )
    ", 
        array(
        10, 
        $metakey, 
        $metavalue
    ) 
) );

Your array should have the same number of elements as your query string has placeholders.

1
  • 1
    The question is asking about select. Commented Jan 23, 2015 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.