spraypray12 Posted March 6, 2007 Share Posted March 6, 2007 Heres my code function grabit() { $mySQL_query2 = "SELECT Requestor FROM ordrfrm WHERE id LIKE" . " $id"; echo "<pre>\n$mySQL_query2\n</pre>"; $f = mysql_query($mySQL_query2); while($row = mysql_fetch_assoc($f)) { echo "Name :{$row['Requestor']} <br>"; } } grabit(); echo $id When i take this code out of a function, it works fine and gets me the results. It's the firsts steps for a little bit bigger function i'll build later, bit i can't get this one working. Any Suggestions? Link to comment https://forums.phpfreaks.com/topic/41509-solved-help-using-php-variables-in-mysql-query-in-a-php-function/ Share on other sites More sharing options...
trq Posted March 6, 2007 Share Posted March 6, 2007 You need to pass the id variable into the function. Your definition would look more like.... function grabit($id) then to call it, use.... grabit(4); Take a look at the manual at the use of functions. Link to comment https://forums.phpfreaks.com/topic/41509-solved-help-using-php-variables-in-mysql-query-in-a-php-function/#findComment-201094 Share on other sites More sharing options...
spraypray12 Posted March 7, 2007 Author Share Posted March 7, 2007 Thanks, wassn't sure i needed to pass the variable, makes sense now that i think about it. I'll remember that one Link to comment https://forums.phpfreaks.com/topic/41509-solved-help-using-php-variables-in-mysql-query-in-a-php-function/#findComment-201901 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.