Question

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'] );
}
?>
Was it helpful?

Solution

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 ) );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top