0

I have the following code:

$userID = get_current_user_id();
        echo $userID;
        $sql ="
        SELECT wp_users.`user_email`,
           wp_wp_pro_quiz_statistic.`correct_count`,
           wp_wp_pro_quiz_statistic.`incorrect_count`,
           wp_wp_pro_quiz_category.`category_name`
        FROM wp_users
          INNER JOIN wp_wp_pro_quiz_statistic_ref
             ON wp_users.`ID` = wp_wp_pro_quiz_statistic_ref.`user_id`
          INNER JOIN wp_wp_pro_quiz_statistic
             ON wp_wp_pro_quiz_statistic_ref.`statistic_ref_id` = wp_wp_pro_quiz_statistic.`statistic_ref_id`
          INNER JOIN wp_wp_pro_quiz_question
             ON wp_wp_pro_quiz_statistic.`question_id` = wp_wp_pro_quiz_question.`id`
          INNER JOIN wp_wp_pro_quiz_category
             ON wp_wp_pro_quiz_question.`category_id` = wp_wp_pro_quiz_category.`category_id`
        WHERE wp_users.`ID` = $[userID]";

How can I correctly pass the current user ID into the WHERE clause?

0

No need to use []... just use simple single quotations (also no quotations does the job):

$sql ="
    SELECT 
    ...
    WHERE wp_users.`ID` = '$userID'";

OR

$sql ="
    SELECT 
    ...
    WHERE wp_users.`ID` = $userID";
| improve this answer | |
  • Thank you! I feel silly now :) – sw123456 Jun 8 at 16:28

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.