0
To automate my process of generating one JSON, i save the variable name in the database (Ex: $teste_value_1
).
In my php file. i have the value of this variable, for example $teste_value_1 = "Isso é um teste";
.
Then I make one query to echo this variable, however, instead of returning me the value of the previously predicted variable in PHP ("This is a test"), it always returns without interpreting the variable, only as text ("$teste_value_1").
Below my data structure to better understand the process:
Table: Attributes
id_attribute | attribue_string | attribute_value
1 | teste_string_1 | $teste_value_1
2 | teste_string_2 | $teste_value_2
Variables:
$teste_value_1 = "Isso é um teste";
$teste_value_2 = "Esse é outro teste";
Query:
$query_array = mysqli_query($connect,"
SELECT GROUP_CONCAT(CONCAT('{id:', a.attribute_string, ',value_name:', a.attribute_value, '}') SEPARATOR ', ') AS concat
FROM rel_categories_attributes AS rca
INNER JOIN categories AS c ON c.id_category = rca.categories_id_category
INNER JOIN attributes AS a ON a.id_attribute = rca.attributes_id_attribute
WHERE id_category = '{$id_category}'
");
WHILE ($reg_cat = mysqli_fetch_array($query_array)){
echo $teste_query = $reg_cat["concat"] . ",";
Upshot:
{id:teste_string_1,value_name:$teste_value_1},
{id:teste_string_2,value_name:$teste_value_2},
Expected result:
{id:teste_string_1,value_name:Isso é um teste},
{id:teste_string_2,value_name:Isso é outro teste},
Perhaps it would be more feasible to save json directly to the database. Saving to the php variable name will not work. php interpolates the variable written to the file under some conditions. A string containing the variable will not be interpreted like this.
– edson alves