0

I'm currently building a website using wordpress that has a personality quiz on it. There is a results page that retrieves the value of the users last submission. I have managed to get it to return the last submission but cant work out how to only return the current users last submission. I think it has something to do with get_currentuserinfo(); and AND user_id = %d", $form_id, $user_ID from what I can work out. I discovered get_currentuserinfo(); here: http://codex.wordpress.org/Function_Reference/get_currentuserinfo

You can see my coding below. Please let me know if you need any further information.

<?php 
global $wpdb, $ipt_fsqm_info, $user_ID;
get_currentuserinfo();
$form_id = 9;
$data_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id 
                                               FROM {$ipt_fsqm_info['data_table']}
                                              WHERE form_id = %d 
                                           ORDER BY id DESC LIMIT 0,1 
                                                AND user_id = %d", $form_id, $user_ID ) );

foreach ( $data_ids as $data_id ) {
    $data = new IPT_FSQM_Form_Elements_Data( $data_id );
    echo wpautop( $data->data->pinfo[14]['value'] );
}
?>

1 Answer 1

3

You need to move the AND user_id = %d

$data_ids = $wpdb->get_col( $wpdb->prepare
( "SELECT id FROM {$ipt_fsqm_info['data_table']} 
WHERE form_id = %d AND user_id = %d 
ORDER BY id DESC LIMIT 0,1", $form_id, $user_ID ) );
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so so much. I have been pulling my hair out for hours on this one.

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.