WordPress variable concatenation then re-use in foreach

I am having a few issues concatenating a string and then outputting the value.

In the database I have a column titled 'featured_price'. In that column is specified another column that will hold the value I am trying to acquire, however, I need to append '_term' to the end and then get the column from the database.

Read More

So I need to have two outputs:

1) featured_price
2) specified_column_term

This is my PHP:

 $rows = $wpdb->get_results("SELECT * FROM specified_details WHERE id='$id'"); 
 foreach ($rows as $result) { 
     echo $result->featured_price;

     $featuredprice = $result->featured_price;
     $featuredterm  = $featuredprice. "_term";

     echo $result->$featuredterm;
 } 

When I var_dump() I just get this array(0).

Related posts

Leave a Reply

1 comment