howdoing Posted March 22, 2008 Share Posted March 22, 2008 Wow, this is driving me nuts. I have been trying different things but with no luck. MY php knowledge is okay and needs huge improvement. Also I am new to php freaks forum. I have this database and i want to pull query out of it. When i query in MYSQL. I.E. if I select RIGHT plan 40 and CORE500 it should give me the value of C.(or X, A w which ever is in the middle, kinda like a multiplication table) However when i try to get the out put via PHP, I am not getting my desired result. I have a slight idea but not sure where to go, and hoping i can get assistance. When I bind the query with the actualy names it gives me an out put of $query="SELECT CORE5000 FROM caplan WHERE plan_name = '(T160) PPO 3500 (HSA-Compatible)'"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $pn1=mysql_result($result,$i); $i++; } echo $pn1; --When this is executed it gives me the desired result. Well i wanted the form to get a dynamic select from a list box, so So i added these and modified my query so now it looks like this: $id=$_POST['plan_name']; // Value being passed $id2=$_POST['plan_name2']; // Second option being passed. $query = "SELECT '$id' from caplan WHERE plan_name = '$id2'"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $pn1=mysql_result($result,$i); $i++; } echo $pn1; I get an output of the plan name(like CORE500 etc.) and not the intersecting value of C, X,A or W. I figured the line: $query = "SELECT '$id' from caplan WHERE plan_name = '$id2'"; is incorrect. IS there a way to SELECT the variables and with out the quotes and mimic exactly how it is pulled out of the mysql command prompt? Am i writing my query incorrectly? Pretty much i want to write a query that will pull the selected data from 2 list boxes and output what matches inthe database picture above. I have the actually program built in excel by some mysterious person so i know it is possible however i am having no such luck porting it over to PHP. Much help is appreciated Thank you in advanced. Link to comment https://forums.phpfreaks.com/topic/97395-phpmysql-database-query-help/ Share on other sites More sharing options...
Barand Posted March 22, 2008 Share Posted March 22, 2008 Don't put column names in quotes, only string values, Use `..` if colnames have spaces in them <?php $query = "SELECT `$id` from caplan WHERE plan_name = '$id2'"; Link to comment https://forums.phpfreaks.com/topic/97395-phpmysql-database-query-help/#findComment-498503 Share on other sites More sharing options...
howdoing Posted March 23, 2008 Author Share Posted March 23, 2008 ahh i see. hmm i still have an issue outputing the query now that i have corrected the `` marks. Link to comment https://forums.phpfreaks.com/topic/97395-phpmysql-database-query-help/#findComment-498653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.