简体   繁体   English

我如何用php替换SQL查询中的表名

[英]How can i replace table name in sql query with php

How can i replace table name in this query string with another string or table name with php 我如何用php替换另一个字符串或表名来代替此查询字符串中的表名

SELECT 
    Panel.Id as PanelId,Panel.Title as PanelTitle,Panel.Icon as PanelIcon,
    SubPanel.Id as SubPanelId,SubPanel.Title as SubPanelTitle,
    SubPanel.Icon as SubPanelIcon,SecurityAccess.Id as Access,SecurityAccess.Controller,
    SecurityAccess.Action
FROM Panel
INNER JOIN SubPanel
INNER JOIN SecurityAccess
WHERE 
Panel.Id > 0 AND SubPanel.Panel = Panel.Id AND SubPanel.Id = UsersAccess.Subpanel
and SubPanel.Id > 0
ORDER BY Panel._Order,SubPanel._Order 

For example: replace "Panel" with "my_panel" 例如:将“ Panel”替换为“ my_panel”

I do not want you to change my String. 我不希望您更改我的字符串。 Just use this string as it exists. 只需使用此字符串即可。

I hope this helps you.. 我希望这可以帮助你..

$sql = "SELECT 
            $table_1.Id as PanelId, $table_1.Title as PanelTitle, $table_1.Icon as PanelIcon,
            $table_2.Id as SubPanelId, $table_2.Title as SubPanelTitle,
            $table_2.Icon as SubPanelIcon, $table_3.Id as Access, $table_3.Controller,
            $table_3.Action
        FROM $table_1
        INNER JOIN $table_2
        INNER JOIN $table_3
        WHERE 
        $table_1.Id > 0 AND $table_2.Panel = $table_1.Id AND $table_2.Id = UsersAccess.Subpanel
        and $table_2.Id > 0
        ORDER BY $table_1._Order, $table_2._Order";

for your current query it would be like.. 对于您当前的查询,它将是..

$table_1 = "Panel";
$table_2 = "SubPanel";
$table_3 = "SecurityAccess";

If $table_ vars are user input than be careful to escape them before putting into query. 如果$ table_ vars是用户输入,则在进行查询之前请小心转义它们。

如何让 id=1,2,3,... 的按钮组替换<!--?php query = “select * from table1”?</div--><div id="text_translate"><p> 我有一个下拉按钮组第 1 课、第 2 课、第 3 课...,当我选择第 1 课时,我希望将 query =“select * from table1”更改为 query =“select * from table2”等等。 我该怎么做?” 非常感谢,我是 mysql 的新手。</p><pre> &lt;div class="dropdown-menu"&gt; &lt;a class="dropdown-item" href="#" onclick="foo()"&gt;lesson1&lt;/a&gt; &lt;a class="dropdown-item" href="#" onclick="foo()"&gt;lesson2&lt;/a&gt; &lt;a class="dropdown-item" href="#" onclick="foo()"&gt;lesson3&lt;/a&gt; &lt;/div&gt; &lt;?php $query = "select * from lesson1"; ?&gt;</pre></div> - How can I let the button group with id=1,2,3,… to replace the <?php query = “select * from table1”?

暂无
暂无

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

相关问题 如何替换sql查询中的表名? - How can i replace the table name in sql query? 如何在 SQL 查询中动态生成表名? - How can I dynamically generate a table name in a SQL query? 无法在 SQL 查询中用变量替换表名 - Can't replace table name with variable in SQL query 如何让 id=1,2,3,... 的按钮组替换<!--?php query = “select * from table1”?</div--><div id="text_translate"><p> 我有一个下拉按钮组第 1 课、第 2 课、第 3 课...,当我选择第 1 课时,我希望将 query =“select * from table1”更改为 query =“select * from table2”等等。 我该怎么做?” 非常感谢,我是 mysql 的新手。</p><pre> &lt;div class="dropdown-menu"&gt; &lt;a class="dropdown-item" href="#" onclick="foo()"&gt;lesson1&lt;/a&gt; &lt;a class="dropdown-item" href="#" onclick="foo()"&gt;lesson2&lt;/a&gt; &lt;a class="dropdown-item" href="#" onclick="foo()"&gt;lesson3&lt;/a&gt; &lt;/div&gt; &lt;?php $query = "select * from lesson1"; ?&gt;</pre></div> - How can I let the button group with id=1,2,3,… to replace the <?php query = “select * from table1”? PHP,MySQL,如何获取动态sql html表循环中的字段名称? - php, mysql, how can I get the field name inside my dynamic sql html table loop? php foreach循环SQL表名查询 - php foreach loop SQL table name query PHP变量作为SQL查询中的表名 - PHP variable as table name in SQL query 如何在PHP的get查询中替换变量? - How can I replace a variable in a get query in PHP? PHP:如何str_replace可变内容查询? - PHP: How can I str_replace a query of variable content? 在php-mysql中,如何在结果表的单元格中合并sql查询的结果? - In php-mysql, How can I union the results of the sql query in a cell of the result table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM