Click here to Skip to main content
15,885,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?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.
Posted
Updated 1-May-21 4:31am
v2

XML
<html>
<head>
   <meta charset="utf-8" />
    <title></title>
</head>
<body>
<?php
print '12544';
?>
</body>
</html>
 
Share this answer
 
Change your code to below.

PHP
<?php
mysql_connect("localhost","root","password");
mysql_select_db("rohan_iksha");
$towerValue_4bhk = $_GET['towerValue_4bhk']; // from AJAX call
$floor_names_query = MYSQL_QUERY("select ".$total_4bhk." from project_master");
mysql_close();
?>



Run below code to check if your query is returning result.

PHP
<?php

$link = mysql_connect("localhost", "root", "password");
mysql_select_db("rohan_iksha", $link);

$result = mysql_query("select total_4bhk from project_master", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>


See what it is returning.
 
Share this answer
 
v4
Comments
Chubby Ninja 23-Dec-14 15:04pm    
where is $total_4bhk defined above? FYI: you can include a variable inside "double quotes" just like the OP has
Janardhanam Julapalli 23-Dec-14 22:03pm    
sorry! MYSQL_QUERY("select $towerValue_4bhk from project_master") is my requirement
Praveen Kumar Upadhyay 23-Dec-14 22:10pm    
Yes. So just change variable name there.
Janardhanam Julapalli 23-Dec-14 22:13pm    
I tried it.But no success.
Praveen Kumar Upadhyay 23-Dec-14 22:20pm    
Try doing echo of that variable before the select statement. I guess that variable has some invalid data.
<?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();
?>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900