Jump to content

Recommended Posts

Hey guys.

I'm kind of new to php, and I'm still at the whole "newbie" stage, however that's obviously not why I create this thread.

 

I'm trying to pull multiple results out of  out of my MySQL table.

Now, to give you an impression of how the table is structured, I'll try to illustrate it.

 

I have 6 rows that i need to pull information out of

 

[id]

[admin]

[user]

[kick]

[ban]

[jail]

 

The [id][admin] and [user] works out just as supposed, the part that I'm stuck with is the [kick] [ban] [jail].

For example

[kick] = 0

[ban] = 0

[jail]  = 1

 

Would mean php should select [jail], which it does, however for some reason it keeps repeaing the first echoed result of the kick,ban,jail if statement.

 

<?
		$query = 'SELECT id,ban,kick,jail,admin,user FROM `adminlog` WHERE user = "'.mysql_real_escape_string($_SESSION['Name']).'" ORDER BY id';
        $query2 = mysql_query('SELECT * FROM `adminlog` WHERE user = "'.mysql_real_escape_string($_SESSION['Name']).'" LIMIT 1');
		$result = mysql_query("$query")
		or die("Table Content Request Failed: " . mysql_error());

    	if($test->kick == 1)
  		{
  			$status = "Ban";
  		}
  		elseif($test->ban == 1)
  		{
  			$status = "Kick";
  		}
  		elseif($test->jail == 1)
  		{
  			$status = "Jailed";
  		}
	if(mysql_num_rows($result) == 0)
		{
			?>
			<i>Archive of kicks/bans/jails is empty</i>
			<?
			return false;
		}
  	 	while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
            {

     			echo 'Action made by: '.$row['admin'].'<br />'.$status.'<br /><br /> ';
     		}
?>

 

as you can see, if i have two results in the table, it would print it out twice.

Now, lets say that the two results are supposed to be

 

Admin1

Jail

 

Admin2

Ban

 

php's output is

 

Admin1

Jail

 

Admin2

Jail

 

So it is repeating the jail part, even though the jail is not matching the second result.

 

 

I'm honestly stuck in this, and would appreciate a little help very much.

(keep in mind functions and so on who is not stated, is stated in a previous header include).

 

/ Daniello.

 

Link to comment
https://forums.phpfreaks.com/topic/163879-pulling-multiple-results-from-mysql/
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.