Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/251642-two-php-questions/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/251642-two-php-questions/#findComment-1290579
Share on other sites

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
}

Link to comment
https://forums.phpfreaks.com/topic/251642-two-php-questions/#findComment-1290586
Share on other sites

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 :("

Link to comment
https://forums.phpfreaks.com/topic/251642-two-php-questions/#findComment-1290588
Share on other sites

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>";
		}
	}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/251642-two-php-questions/#findComment-1290593
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.