简体   繁体   English

如何获取表中存储的SQL查询并为表中的所有查询创建动态PHP页面

[英]How can retrieve sql query which stored in table and make dynamic php page for all queries in table

I'm trying to retrieve dynamic query PHP pages. 我正在尝试检索动态查询PHP页面。 First page passing values of city or id next page by post method. 首页通过post方法传递城市或id的值的下一页。

Table looks like this: 表看起来像这样:

TABLE1 表格1

-----------------------------------------------------
1     select * from tablename1 where ID = $id
2     select * from tablename1 where city = $city
-----------------------------------------------------

Now I run page contain code: 现在我运行页面包含代码:

    $id = $_POST["id"];
    $city= $_POST["city"];
    $tabledata = mysql_query("SELECT * FROM table1 ");
    $a=mysql_fetch_row($tabledata );

    $query_table=$a['1']; // retrieve sql query from table1 which stored in 2nd column
    echo " $query_table"; // display query
    $result = mysql_query($query_table);

    while ($field = mysql_fetch_row( $result) )
    {
        echo "<td> $field[1] </td>";
    }

Now, the problem is that I can't get results. 现在,问题是我无法获得结果。 $result is empty? $result是否为空?

How pass $city or $id value to query? 如何传递$city$id值进行查询?

But if I remove WHERE condition from TABKE1 then it works well. 但是,如果我从TABKE1中删除WHERE条件,则它会很好地工作。 So, how can I make for WHERE condition to pass parameters? 那么,如何使WHERE条件传递参数?

how can i do this . 我怎样才能做到这一点 。 any other option here to call stored query on 1 table and process it on other page and oher table 此处的任何其他选项可以在1个表上调用存储的查询,并在其他页面和其他表上处理它

在第一个语句中使用WHEREOR子句,然后可以迭代作为行返回的每个结果,并且可以避免上面的复杂方法。

$tabledata = mysql_query("SELECT * FROM table1 WHERE ID = {$id} OR city = {$city}");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM