php – Why can’t I return a value from $wpdb->get var?


I am trying to delete a record from a table when a condition is met. The condition is this: If there is a record in Table 1 that fails to match a record in Table 2, then delete the record from Table 1.

$survey_mapping =$wpdb->get_results( $wpdb->prepare("SELECT surveyid from oc_partner_x_survey")); 
 foreach($survey_mapping as $row){
     $dup_survey2 =absint($wpdb->get_var( $wpdb->prepare("SELECT surveyls_survey_id FROM oc_surveys_languagesettings WHERE surveyls_survey_id =%d",$row)));   
    if (absint($dup_survey2) > 0) { 
        $error_msg1[] = $dup_survey2;
    } else {
        $error_msg2[0] = $row;
        $error_msg2[1] = $dup_survey;
        $error_msg2[2] = $survey_mapping;

        array('surveyid' => absint($row)),array('%d'));     

This is from the console. You can see how the variable $dup_survey is null.


Here is Table 1:
enter image description here

Here is Table 2:
enter image description here

I am stuck. Any help or insight would be most appreciated! Thank you!

David Weisser 1 month 2021-06-26T13:47:13-05:00 0 Answers 0 views 0

Leave an answer