0

The DB columns are |name|userID|lastname|UserPass|age|gender| i am building a query to select multiple results in one request

   global $wpdb;

   $res = $wpdb->get_results( $wpdb->prepare(
        "SELECT name, lastname
         FROM datatable
         WHERE userID in ( %d , %d)
         AND
         UserPass in ( %d, %d  )",
         array(
            $val[1],
            $val[2],
            $val[3],
            $val[4],
         )

        ),
        ARRAY_A
    );

where $val[1] and $val[2] should be uset as userID, and $val[3] and $val[4] UserPass. And i think i have problem with ordering the placeholder values and that the query is not setup properly, could use a word of advice.

2
  • its a simple PDO statement or word-press prepare statement ? Commented Sep 4, 2015 at 11:24
  • its simple, i was using the prepare only because of the placeholders Commented Sep 4, 2015 at 11:30

2 Answers 2

1

Try with this :

 $querystr = "
    SELECT name, lastname
         FROM datatable
         WHERE userID in ('your user ids implode with commas')
         AND
         UserPass in ('password string implode with commas ')
 ";

 $result = $wpdb->get_results($querystr, OBJECT);
Sign up to request clarification or add additional context in comments.

Comments

0

This query returns all the users that match the given passwords.

<?php
    global $wpdb;

   $res = $wpdb->get_results( $wpdb->prepare(
        "SELECT name, lastname, UserPass
         FROM datatable
         WHERE userID in ( %d , %d)
         HAVING UserPass in ( %d, %d  )",
         array(
            $val[1],
            $val[2],
            $val[3],
            $val[4],
         )

        ),
        ARRAY_A
    );
?>

Maybe this helps?

1 Comment

I need only there name and last name, and what i wanted to know rly was if the structure is good and if the placeholder values are writen good, so if WHERE userID in ( $val[1] , $val[2]) AND UserPass in ( $val[3], $val[4] )" has that order of reading

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.