CodeToad Posted May 31, 2007 Share Posted May 31, 2007 Here is what I'm trying to do: $temp = 5; $sql = 'SELECT * FROM database WHERE numid = "$temp"'; It doesn't work since I'm trying to assign a variable inside a variable, does anyone have any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/53771-solved-how-to-add-a-variable-inside-a-select-query/ Share on other sites More sharing options...
redarrow Posted May 31, 2007 Share Posted May 31, 2007 $temp = 5; $sql = "SELECT * FROM database WHERE numid = '$temp' "; Quote Link to comment https://forums.phpfreaks.com/topic/53771-solved-how-to-add-a-variable-inside-a-select-query/#findComment-265792 Share on other sites More sharing options...
Lumio Posted May 31, 2007 Share Posted May 31, 2007 You can use one of them: $sql = 'SELECT * FROM database WHERE numid = "'.$temp.'"'; $sql = "SELECT * FROM database WHERE numid = '$temp'"; $sql = "SELECT * FROM database WHERE numid = '".$temp."'"; Quote Link to comment https://forums.phpfreaks.com/topic/53771-solved-how-to-add-a-variable-inside-a-select-query/#findComment-265793 Share on other sites More sharing options...
CodeToad Posted May 31, 2007 Author Share Posted May 31, 2007 Thanks for the quick responses guys! I had been google searching for a while with no luck. I figured it was just syntax issues, but I'm new to this and didn't know any better. You saved me a bunch of time, thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/53771-solved-how-to-add-a-variable-inside-a-select-query/#findComment-265797 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.