Daney11 Posted March 1, 2008 Share Posted March 1, 2008 Hey guys, Im trying to write a funtion to grab a members username based on the members ID function member_username($get_username) { if($get_username == '0') { return "Not Used"; } $getmemberQuery = "SELECT * FROM members WHERE member_id = $get_username"; $getmemberresult = mysql_query($getmemberQuery, $connect) or die(mysql_error()); $num_rows = mysql_num_rows($getmemberresult); if ($num_rows > 0) { $member_username = mysql_fetch_array($getmemberresult); extract($member_username); return "$member_username"; } else { return "Error"; } } That does nothing at the moment. Anyideas? Thanks Link to comment https://forums.phpfreaks.com/topic/93839-function/ Share on other sites More sharing options...
paul2463 Posted March 1, 2008 Share Posted March 1, 2008 when and where is $connect passed to the function????? is probably dies inside the function Link to comment https://forums.phpfreaks.com/topic/93839-function/#findComment-480827 Share on other sites More sharing options...
Daney11 Posted March 1, 2008 Author Share Posted March 1, 2008 i tried this one aswell function member_username($get_username) { if($get_username == '0') { return "Not Used"; } $getmemberQuery = "SELECT * FROM members WHERE member_id = $get_username"; $getmemberresult = mysql_query($getmemberQuery, $connect) or die(mysql_error()); while ($getmemberrow = mysql_fetch_array($getmemberresult)) { // Start Member While Loop $member_id = escape_data(htmlentities($getmemberrow['member_id'])); $member_teamid = escape_data(htmlentities($getmemberrow['member_teamid'])); $member_username = escape_data(htmlentities($getmemberrow['member_username'])); } return "$member_username"; } Link to comment https://forums.phpfreaks.com/topic/93839-function/#findComment-480829 Share on other sites More sharing options...
Daney11 Posted March 1, 2008 Author Share Posted March 1, 2008 At the top of the page i included settings.php which has my mysql connection inside it, using $connect. Link to comment https://forums.phpfreaks.com/topic/93839-function/#findComment-480830 Share on other sites More sharing options...
paul2463 Posted March 1, 2008 Share Posted March 1, 2008 then use function member_username($get_username, $connect) { //function body } and pass it the $connect statement in your function call Link to comment https://forums.phpfreaks.com/topic/93839-function/#findComment-480831 Share on other sites More sharing options...
Daney11 Posted March 1, 2008 Author Share Posted March 1, 2008 Fixed, thanks, i took $connect out of there. Link to comment https://forums.phpfreaks.com/topic/93839-function/#findComment-480832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.