如何在MYSQL中的select查询中使用PHP变量作为列名? [英] How to use a PHP variable as a column name in select query in MYSQL?
本文介绍了如何在MYSQL中的select查询中使用PHP变量作为列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php
mysql_connect( localhost, root,< span class =code-string> password);
mysql_select_db( db_name);
$ towerValue_4bhk = $ _GET [' towerValue_4bhk 跨度>];来自AJAX调用的 //
$ floor_names_query = MYSQL_QUERY( 从project_master选择$ total_4bhk);
mysql_close();
?>
我想要$ towerValue_4bhk在SELECT Query中用作列名。
当用户在前端选择4BHK时,我应该显示15层可用的4BHK的数量。
解决方案
towerValue_4bhk =
_GET [' towerValue_4bhk'跨度>];来自AJAX调用的 //
floor_names_query = MYSQL_QUERY( select
<?php
mysql_connect("localhost","root","password");
mysql_select_db("db_name");
$towerValue_4bhk = $_GET['towerValue_4bhk']; // from AJAX call
$floor_names_query = MYSQL_QUERY("select $total_4bhk from project_master");
mysql_close();
?>
I want $towerValue_4bhk to be used as a column name in SELECT Query.
When user selects a 4BHK in the front end then I should display the no of 4BHK's available for 15 floors.
解决方案
towerValue_4bhk =
_GET['towerValue_4bhk']; // from AJAX call
floor_names_query = MYSQL_QUERY("select
这篇关于如何在MYSQL中的select查询中使用PHP变量作为列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文