php - $wpdb->get_results($query); Returns NULL with variable $query - Same query works hardcoded -


i've been trying debug script month. rest of program built , 1 thing not work. issue $query variable, returns null unless hard code - isn't possible search form. i've tried adding '\n', i've tried putting in returns, i've changed " ' beginning. i've tested rest of code outside of block , works. i've run tests on block can see commented out echo statements below. test fine. $query string built function returns correct data when hard coded or in database browser. i'm stuck! please.

[code snippet]

if(isset($_post['submit'])) {      // define list of fields     $fields = array('lastname', 'firstname', 'dob', 'city', 'telephone', 'email', 'user_id');     $conditions = array();       // loop through defined fields     foreach($fields $field){         //echo "field ".$field."\n";         // if field set , not empty         if(isset($_post[$field]) && $_post[$field] != '') {               //echo "field is: ".$field."\n".$field." is: ".$_post[$field]."\n";                         // create new condition while escaping value inputed user (sql injection)             $conditions[] = "$field '%" . mysql_real_escape_string($_post[$field]) . "%'              ";         }     }      // builds query     $query = "\"     select *      wp_ct_ad_client_db_table     ";      // if there conditions defined    $query_user_id = "user_id = ".$user_id."    \"";     array_push($conditions, $query_user_id);      if(count($conditions) > 0) {         // append conditions         $query .= "where " . implode(' , ', $conditions); // can change 'or', suggest apply filters cumulative     }      echo "query string: ".$query."\n";      //$result = $wpdb->get_results($query);     $my_query = $query;      echo "test query logic \n";     //$result = $wpdb->get_results("select * wp_ct_ad_client_db_table lastname '%a%' , user_id = $user_id;");     //$result = $wpdb->get_results($my_query);     $result = $wpdb->get_results($my_query, a_array);      var_dump($result); 

[/code snippet]


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -