Reputation: 1930
I have a query string that contains a variable like this
$field_name = 'features';
$value = '5';
$query = "SELECT * FROM Table WHERE $field_name\_tid = '$value'";
My goal is to print out the $query
like this SELECT * FROM Table WHERE features_tid = '5';
I put \_
there hoping it would work as escape character, but it didn't work. Is there any way to achieve this without use methods like ". $field_name ."
and modifying original variable value?
Upvotes: 1
Views: 123
Reputation: 6224
You can use:
$query = "SELECT * FROM Table WHERE {$field_name}_tid = '$value'";
Upvotes: 1
Reputation: 748
yes:
$query = "SELECT * FROM Table WHERE {$field_name}_tid = '$value'";
Upvotes: 2