mrherman Posted July 15, 2008 Share Posted July 15, 2008 Hello again, friends.... I have a function that requires one parameter: an "m" or an "r". If the parameter is an "m", I want to access the db field "mtotcor." If the parameter is an "r", I want to access the db field "rtotcor." The following throws an error: $sql = "SELECT $param . totcor FROM..." How can I take the passed $param and combine it with "totcor" to make "mtotcor" or "rtotcor" that can be used in the SQL SELECT statement? Thank ya!! Link to comment https://forums.phpfreaks.com/topic/114769-solved-using-a-quotvariable-combinationquot-within-an-sql-statement/ Share on other sites More sharing options...
sader Posted July 15, 2008 Share Posted July 15, 2008 $sql = "SELECT $param.totcor FROM..." don't use spaces between . Link to comment https://forums.phpfreaks.com/topic/114769-solved-using-a-quotvariable-combinationquot-within-an-sql-statement/#findComment-590124 Share on other sites More sharing options...
mrherman Posted July 15, 2008 Author Share Posted July 15, 2008 Thanks, sader I tried your suggestion, $sql = "SELECT $param.totcor FROM..." This doesn't seem to work....If the $param is an "m", the error is "Unknown column m.totcor..."... Thanks!! Link to comment https://forums.phpfreaks.com/topic/114769-solved-using-a-quotvariable-combinationquot-within-an-sql-statement/#findComment-590132 Share on other sites More sharing options...
sader Posted July 15, 2008 Share Posted July 15, 2008 $sql = "SELECT $param"."totcor FROM..."; maybe like this :] Link to comment https://forums.phpfreaks.com/topic/114769-solved-using-a-quotvariable-combinationquot-within-an-sql-statement/#findComment-590133 Share on other sites More sharing options...
mrherman Posted July 15, 2008 Author Share Posted July 15, 2008 Hi, Sader... Y-E-E-S-S-S-S!! That is the solution. Thanks so much for staying on the case! See ya next time! Link to comment https://forums.phpfreaks.com/topic/114769-solved-using-a-quotvariable-combinationquot-within-an-sql-statement/#findComment-590138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.