NLT Posted November 22, 2011 Share Posted November 22, 2011 Hello, I've currently got this: <?php $GetRanks = mysql_query("SELECT id,name FROM ranks WHERE id > 2 AND id != 8 ORDER BY id DESC"); while($Ranks = mysql_fetch_assoc($GetRanks)) { echo "<div class=\"habblet-container \"><div class=\"cbb clearfix blue \"><h2 class=\"title\">{$Ranks['name']}s</h2><div style=\"padding:5px\"><p>"; $GetUsers = mysql_query("SELECT username,motto,rank,last_online,online,look FROM users WHERE rank = {$Ranks['id']}"); $GetBio = mysql_query("SELECT bio FROM staff_bio WHERE userid ={$Users['id']}"); $GetBioo = mysql_fetch_assoc($GetBio); while($Users = mysql_fetch_assoc($GetUsers)) { if($Users['online'] == 1){ $OnlineStatus = "<font color=\"darkgreen\"><b>Online</b></font>"; } else { $OnlineStatus = "<font color=\"darkred\"><b>Offline</b></font>"; } ."<p style=\"margin-left:80px;margin-top:20px;\">Username: <strong>{$Users['username']}</strong><br>Motto: <strong>{$Users['motto']}</strong><br><small>Last Online: ". date("D, d F Y H:i (P)", $Users['last_online']) ."</small></p>" ."Bio: <strong>{$staff_bio['bio']}</strong>" ."<p style=\"float:right;margin-top:-30px;margin-right:5px;\">{$OnlineStatus}</p><br><br><br>"; } echo "</div></div></div>"; } ?> The two problems I am having, is getting text from the column bio from the table staff_bio. It's giving me this: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in line 96 The second problem I am having, is displaying the ranks which haven't got anyone in. I used a query like: $GetUsers = mysql_query("SELECT username,motto,rank,last_online,online,look FROM users WHERE rank = {$Ranks['id']}"); $GetUserss = mysql_query("SELECT * FROM `users` WHERE rank = {$Ranks['id']}"); $Userss = mysql_num_rows($GetUserss); if($Userss < 1) { echo "We're low on staff"; } But if I did it > 1 it shows "We're low on staff" on the ones which aren't empty, so the query is working. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2011 Share Posted November 22, 2011 You give mysql_fetch_assoc() the value of mysql_query(), then mysql_fetch_assoc() returns an error stating that it was given a boolean. mysql_query() will return a result resource if the query executes successfully, or boolean FALSE if the query fails. What do you think might be happening? mysql_error Quote Link to comment Share on other sites More sharing options...
NLT Posted November 22, 2011 Author Share Posted November 22, 2011 I'm not sure what could be happening. I've tried a few things, but not getting anywhere. Quote Link to comment Share on other sites More sharing options...
unlishema.wolf Posted November 22, 2011 Share Posted November 22, 2011 Your error is probably occurring with this. $GetBio = mysql_query("SELECT bio FROM staff_bio WHERE userid ={$Users['id']}"); $GetBioo = mysql_fetch_assoc($GetBio); Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2011 Share Posted November 22, 2011 Reformat your code to make it easier to debug. In this manner, you can echo the query string along with any errors returned by MySQL. $query = "SELECT field FROM table"; if( !$result = mysql_query($query) ) { echo "<br>Query: $query<br>Failed with error: " . mysql_error() . '<br>'; } else { $while( $array = mysql_fetch_assoc($result) ) { // your echo or whatever } Quote Link to comment Share on other sites More sharing options...
NLT Posted November 22, 2011 Author Share Posted November 22, 2011 Your error is probably occurring with this. $GetBio = mysql_query("SELECT bio FROM staff_bio WHERE userid ={$Users['id']}"); $GetBioo = mysql_fetch_assoc($GetBio); Explain. @Latest post - I don't know what you mean. Do you have any idea what I'm doing wrong or what is going wrong? That's the way the code came, I'm just adding a couple of lines (Bio and "We're low on staff " Quote Link to comment Share on other sites More sharing options...
unlishema.wolf Posted November 22, 2011 Share Posted November 22, 2011 Try this code and see what it outputs. <?php $RankQuery="SELECT id,name FROM ranks WHERE id > 2 AND id != 8 ORDER BY id DESC"; if( !$GetRanks = mysql_query($RankQuery) ) { echo "<br>Query: $RankQuery<br>Failed with error: " . mysql_error() . '<br>'; } else { while($Ranks = mysql_fetch_assoc($GetRanks)) { echo "<div class=\"habblet-container \"><div class=\"cbb clearfix blue \"><h2 class=\"title\">{$Ranks['name']}s</h2><div style=\"padding:5px\"><p>"; $UserQuery="SELECT username,motto,rank,last_online,online,look FROM users WHERE rank = {$Ranks['id']}"; if( !$GetUsers = mysql_query($UserQuery) ) { echo "<br>Query: $UserQuery<br>Failed with error: " . mysql_error() . '<br>'; } else { $BioQuery="SELECT bio FROM staff_bio WHERE userid ={$Users['id']}"; if( !$$GetBio = mysql_query($BioQuery) ) { echo "<br>Query: $BieQuery<br>Failed with error: " . mysql_error() . '<br>'; } else { $GetBioo = mysql_fetch_assoc($GetBio); while($Users = mysql_fetch_assoc($GetUsers)) { if($Users['online'] == 1){ $OnlineStatus = "<font color=\"darkgreen\"><b>Online</b></font>"; } else { $OnlineStatus = "<font color=\"darkred\"><b>Offline</b></font>"; } echo "<p style=\"margin-left:80px;margin-top:20px;\">Username: <strong>{$Users['username']}</strong><br>Motto: <strong>{$Users['motto']}</strong><br><small>Last Online: ". date("D, d F Y H:i (P)", $Users['last_online']) ."</small></p>" ."Bio: <strong>{$staff_bio['bio']}</strong>" ."<p style=\"float:right;margin-top:-30px;margin-right:5px;\">{$OnlineStatus}</p><br><br><br>"; } echo "</div></div></div>"; } } } ?> 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.