Kieran-R Posted December 20, 2010 Share Posted December 20, 2010 Hello Well I was trying to make a function where it would make the URL, staff colours, and donator image appear. Although ive ran into a problem. Ive never really attempted to work with functions before, but this is what I came up with: function username_formatter($username) { $USER=mysql_query("SELECT * FROM users WHERE username=$username"); $FETCH=mysql_fetch_array($USER); if($FETCH['donatordays']&&$FETCH['user_level']==1) { $FETCH['username'] = "<font color=white>[b]{$FETCH['username']}[/b]</font>";$d="[img=donator.gif]"; } if($FETCH['user_level']==2) { $FETCH['username'] = "<font color=red>[b]{$FETCH['username']}[/b]</font>";$d="[img=donator.gif]"; } if($FETCH['user_level']==5) { $FETCH['username'] = "<font color=#00FF00>[b]{$FETCH['username']}[/b]</font>";$d="[img=donator.gif]"; } if($FETCH['gang']>0){ $gang=mysql_query("SELECT * FROM gangs WHERE gangID={$FETCH['gang']}"); $gn=mysql_fetch_array($gang); $gangtag="[url='gangs.php?action=gang_view&gang_id={$FETCH['][{$gn['gangPREF']}][/url]"; } else { $gangtag=""; } $user="$gangtag <a href=viewuser?u={$FETCH['userid']} />{$FETCH['username']}</a> $d"; return $user; } to use this function, I would do: username_formatter(***USERNAME***). But it just displays nothing. Yes. I am printing it correctly lol If someone could assist me then it would be much appreciated! Quote Link to comment Share on other sites More sharing options...
Danny696 Posted December 20, 2010 Share Posted December 20, 2010 Try this: function username_formatter($username) { $USER=mysql_query("SELECT * FROM users WHERE username=$username"); $FETCH=mysql_fetch_array($USER); if($FETCH['donatordays']&&$FETCH['user_level']==1) { $FETCH['username'] = "<font color=white>[b]{$FETCH['username']}[/b]</font>";$d="[img=donator.gif]"; } if($FETCH['user_level']==2) { $FETCH['username'] = "<font color=red>[b]{$FETCH['username']}[/b]</font>";$d="[img=donator.gif]"; } if($FETCH['user_level']==5) { $FETCH['username'] = "<font color=#00FF00>[b]{$FETCH['username']}[/b]</font>";$d="[img=donator.gif]"; } if($FETCH['gang']>0){ $gang=mysql_query("SELECT * FROM gangs WHERE gangID={$FETCH['gang']}"); $gn=mysql_fetch_array($gang); $gangtag="[url='gangs.php?action=gang_view&gang_id={$FETCH['][{$gn['gangPREF']}][/url]"; } else { $gangtag=""; } echo "$gangtag <a href=viewuser?u={$FETCH['userid']} />{$FETCH['username']}</a> $d"; } Quote Link to comment Share on other sites More sharing options...
Kieran-R Posted December 20, 2010 Author Share Posted December 20, 2010 Hmm Im getting an error from: $FETCH=mysql_fetch_array($USER); Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Cant seem to se why that would be erroring though... Quote Link to comment Share on other sites More sharing options...
Danny696 Posted December 20, 2010 Share Posted December 20, 2010 Show me the part where your using the function Quote Link to comment Share on other sites More sharing options...
Kieran-R Posted December 20, 2010 Author Share Posted December 20, 2010 echo "Welcome Back ".username_formatter($ir['username'])."!"; Quote Link to comment Share on other sites More sharing options...
Kieran-R Posted December 20, 2010 Author Share Posted December 20, 2010 Ahh. I found the error. Its because in teh MySQL query, i put a string on its own instead of surrounding it with ' ' Quote Link to comment Share on other sites More sharing options...
SilvaTungDevil Posted December 20, 2010 Share Posted December 20, 2010 Line 3 and line 9. You are fetching EVERYTHING from the users and gang tables, only having briefly scanned your function I suspect you dont need every column. My suggestions, optimize it a bit and only grab the columns that you need: So maybe [mysql]SELECT `userid`, `username`, `user_level`, `donatordays`, `gang` FROM `users` WHERE `username` = $username[/mysql] And also [mysql]SELECT `gangID`, `gangPREF` FROM `gangs` WHERE `gangID` = {$FETCH['gang']} [/mysql] Quote Link to comment 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.