Sorry if the answer to this question is blindingly obvious, Iâve only just started learning Php so Iâm not 100% sure on what Iâm doing.
Iâve got a quiz that users fill out on wordpress using the plugin FSQM Pro and when they submit it they are redirected to a page that will display some text along with their answer to a question in the quiz. To recall the answer they submit, I have used this code:
<?php global $wpdb, $ipt_fsqm_info;
$form_id = 9;
$data_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$ipt_fsqm_info['data_table']} WHERE form_id = %d", $form_id ) );
foreach ( $data_ids as $data_id ) {
$data = new IPT_FSQM_Form_Elements_Data( $data_id );
echo wpautop( $data->data->pinfo[13]['value'] );
}
?>
However when I execute it, it returns all the values that the user has ever entered for that question with the most recent value at the bottom.
How do I get it to output only the most recent value?
Well, you can modify your MySQL query, by using
ORDER BY
andLIMIT
clauses, like this:$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", $form_id ) );