I have a need to build a dynamic query that requires a variable to structured like so;
$my_var = $var_1.'_'.$var_2.'_band_'.$var_3;
$my_var is then used within a loop.
While I can echo the $my_var data successfully, this does not work in my loop. Is this even a possibility?
Here is the actual loop. $my_var would be used as a lookup for a column title. The vars used in $my_var would be strings.
global $wpdb;
$my_var = $var_1.'_'.$var_2.'_band_'.$var_3;
$results = $wpdb->get_results ( "SELECT * FROM quote WHERE Postcode_area LIKE '%$find%'" );
foreach ( $results as $result ) {
$savings = $result->$my_var * 52;
}
SOLVED
Thank you everyone for your input, I’m sorry to say I was being a complete idiot! The column I was using to lookup data as a test did not required one additional VAR. Truly sorry to waste anyones time!
The loop is now working without issue.
As I mentioned in my comment, try using braces:
This practice is demonstrated in the manual a quarter of the way down under the “Complex (curly) syntax”: http://php.net/manual/en/language.types.string.php