我正在尝试根据先前查询中获得的值进行查询。这样的事情:
$variableid = 100;
$query_prev = "SELECT query FROM queries_table WHERE id = 1";
$result_prev = pg_query($pg,$query_prev);
$row_prev = pg_fetch_array($result_prev);
$final_query = $row_prev['query'];
$row_prev['query'] value would be "SELECT * FROM other_table WHERE id = $variableid";
$final_query value at this point is: "SELECT * FROM other_table WHERE id = $variableid"
/* but that I want is this value: */ "SELECT * FROM other_table WHERE id = 100"
答案 0 :(得分:0)
在进行下一次选择之前使用if语句:
<?php if ($row_prev['query']= 100){
SELECT .......... etc.
}else
SELECT from other
?>
/希望这就是你想要的
答案 1 :(得分:0)
解决:
$variableid = 100;
$query_prev = "SELECT query FROM queries_table WHERE id = 1";
$result_prev = pg_query($pg,$query_prev);
$row_prev = pg_fetch_array($result_prev);
$query = $row_prev['query'];
eval("\$final_query = \"$query\";");