rollOrDie Posted June 28, 2008 Share Posted June 28, 2008 I have an SQL statement like so: "SELECT portTitle FROM tblPort WHERE portId = '$portId'" But I would like to use something like this: "SELECT $fieldName FROM tblPort WHERE portId = '$portId'" So that the field can vary depending on the code before it. Does anyone know if or how this is possible?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/112364-using-variables-in-sql-statements/ Share on other sites More sharing options...
.josh Posted June 28, 2008 Share Posted June 28, 2008 Yes it's possible. You just did it. Pat yourself on the back and have a scooby snack. Hey, that rhymes. Quote Link to comment https://forums.phpfreaks.com/topic/112364-using-variables-in-sql-statements/#findComment-576899 Share on other sites More sharing options...
LooieENG Posted June 28, 2008 Share Posted June 28, 2008 <?php $fieldName = mysql_real_escape_string($_POST['fn']); "SELECT '$fieldName' FROM tblPort WHERE portId = '$portId'" ?> is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/112364-using-variables-in-sql-statements/#findComment-576901 Share on other sites More sharing options...
rollOrDie Posted June 28, 2008 Author Share Posted June 28, 2008 Yes it's possible. You just did it. Pat yourself on the back and have a scooby snack. Hey, that rhymes. Wow so it does work! I tied something before [being sure that it was that] and it never worked! Who knows what I typed... Thanks for the replies anyway Quote Link to comment https://forums.phpfreaks.com/topic/112364-using-variables-in-sql-statements/#findComment-576911 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.