thefollower Posted December 13, 2007 Share Posted December 13, 2007 I have a while loop where by it gets the ID of the user then theres query to get the username of the useid how ever the query is in the while loop so it lags the page alot.. what is the best way to avoid the while loop constantly loading this query but also using the query to obtain the username... this is the while loop.. or the part which im on about: while($row = mysql_fetch_assoc($GetReports)){ $RecordID = $row['RecordID']; $Info = $row['Log']; $ReportedPlayer = $row['ReportedPlayer']; //Get name $GetUserName = mysql_query("SELECT * FROM userregistration WHERE UserID='$ReportedPlayer'") or die(mysql_error()); $UserNameRow = mysql_fetch_assoc($GetUserName); $ReportedPlayer = $UserNameRow['Username']; Is there a better method than this to get username? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 13, 2007 Share Posted December 13, 2007 Don't select everything from the the userregistration table. If you are only want to return the Username then define just the Username column in your query rather than Select all (*) $GetUserName = mysql_query("SELECT Username FROM userregistration WHERE UserID='$ReportedPlayer'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
thefollower Posted December 13, 2007 Author Share Posted December 13, 2007 Is that still possible if you only wanted say 4 fields... ? or would you have to do * then ? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 13, 2007 Share Posted December 13, 2007 No you can just list them within your query, just separate your columns with a comma, eg: SELECT Username, col1, col2, col3 FROM userregistration WHERE UserID='$ReportedPlayer' Quote Link to comment Share on other sites More sharing options...
thefollower Posted December 13, 2007 Author Share Posted December 13, 2007 Thanks! 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.