• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Guilds.php error

Isnal

New Member
Joined
Sep 12, 2008
Messages
45
Reaction score
0
Location
Austria
I've asked some friends of mine if they could help me with solving this problem, but no1 is good in php :/
So this is the error:

Warning: current() [function.current]: Passed variable is not an array or object in C:\xampp\htdocs\nica\guilds.php on line 115

It appears when a guilds gets members, when they join the guild...
the guild exists on homepage but no player is in the guild then, means if u "look" at them, they are guildless tho they've joined the guild on the homepage.

Here's the guilds.php

PHP:
include ("include.inc.php");
$ptitle="Guilds - $cfg[server_name]";
include ("header.inc.php");
$SQL = new SQL();
?>
<div id="content">
<div class="top">Guilds</div>
<div class="mid">
<form method="get" action="guilds.php"> 
<input type="text" name="guild_name"/> 
<input type="submit" value="Search"/> 
</form>
<hr style="margin-top: 5px; margin-bottom: 5px; "/>
<?php 
//-----------------------Guild list
if (!isset($_GET['guild_id']) && !isset($_GET['guild_name'])){
$query = 'SELECT guilds.id, guilds.name, nicaw_guild_info.description FROM guilds LEFT JOIN nicaw_guild_info ON guilds.id = nicaw_guild_info.id ORDER BY name ASC';
$SQL->myQuery($query);
if ($SQL->failed())
	throw new Exception('SQL query failed:<br/>'.$SQL->getError());
while ($a = $SQL->fetch_array()){
if (file_exists('guilds/'.$a['id'].'.gif')) 
	$img_path = 'guilds/'.$a['id'].'.gif';
else
	$img_path = 'ico/guild_default.gif';
?>
<table border="1" onclick="window.location.href='guilds.php?guild_id=<?php echo urlencode($a['id'])?>'" style="cursor: pointer; width: 100%;">
<tr><td style="width: 64px; height: 64px; padding: 10px;"><img src="<?php echo $img_path?>" alt="NO IMG" height="64" width="64"/></td>
<td style="vertical-align: top;">
<b><?php echo htmlspecialchars($a['name'])?></b><hr/>
<?php echo htmlspecialchars($a['description'])?>
</td></tr>
</table>
	
<?php }
}else{
//-------------------------Member list
$guild = new Guild();
if (!empty($_GET['guild_id']) && !$guild->load($_GET['guild_id']))
	echo 'Guild not found.';
elseif (!empty($_GET['guild_name']) && !$guild->find($_GET['guild_name']))
	echo 'Guild not found.';
else{
if (file_exists('guilds/'.$guild->getAttr('id').'.gif')) 
	$img_path = 'guilds/'.$guild->getAttr('id').'.gif';
else
	$img_path = 'ico/guild_default.gif';
?>
<table style="width: 100%"><tr><td style="width: 64px; height: 64px; padding: 10px;"><img src="<?php echo $img_path?>" alt="Guild IMG" height="64" width="64"/></td><td style="text-align: center">
<h1 style="display: inline"><?php echo htmlspecialchars($guild->getAttr('name'))?>
</h1></td><td style="width: 64px; height: 64px; padding: 10px;">
<img src="<?php echo $img_path?>" alt="Guild IMG" height="64" width="64"/></td></tr>
</table>
<p><?php echo htmlspecialchars($guild->getAttr('description'))?></p><hr/>
<ul class="task-menu" style="width: 200px;">
<li style="background-image: url(ico/book_previous.png);" onclick="self.window.location.href='guilds.php'">Back</li>
<?php 
if (!empty($_SESSION['account'])){
	$account = new Account();
	if (!$account->load($_SESSION['account'])) die('Cannot load account');
	$invited = false;
	$member = false;
	foreach ($account->players as $player){
		if ($guild->isInvited($player['id']))
			$invited = true;
		if ($guild->isMember($player['id']))
			$member = true;
	}
	if ($guild->getAttr('owner_acc') == $_SESSION['account']){?>
<li style="background-image: url(ico/user_go.png);" onclick="ajax('form','modules/guild_invite.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Invite Player</li>
<li style="background-image: url(ico/group_delete.png);" onclick="ajax('form','modules/guild_kick.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Kick Member</li>
<li style="background-image: url(ico/user_edit.png);" onclick="ajax('form','modules/guild_edit.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Edit Member</li>
<li style="background-image: url(ico/image_add.png);" onclick="ajax('form','modules/guild_image.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Upload Image</li>
<li style="background-image: url(ico/page_edit.png);" onclick="ajax('form','modules/guild_comments.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Edit Description</li>
<?php 	}
	if ($invited){?>
<li style="background-image: url(ico/user_red.png);" onclick="ajax('form','modules/guild_join.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Join Guild</li>
<?php 	}
	if ($member){?>
<li style="background-image: url(ico/user_delete.png);" onclick="ajax('form','modules/guild_leave.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Leave Guild</li>
<?php 	}?>
<li style="background-image: url(ico/resultset_previous.png);" onclick="self.window.location.href='login.php?logout&amp;redirect=account.php'">Logout</li>
<?php }else{?>
<li style="background-image: url(ico/resultset_next.png);" onclick="self.window.location.href='login.php?redirect=guilds.php'">Login</li>
<?php }?>
</ul><hr/>
<h2 style="display: inline">Guild Members</h2>
<table style="width: 100%">
<tr class="color0"><td style="width: 30%"><b>Rank</b></td><td style="width: 70%"><b>Name and Title</b></td></tr>
<?php 
foreach ($guild->members as $a)
	$members[$a['rank']][] = array('id' => $a['id'], 'name' => $a['name'], 'nick' => $a['nick']);
foreach ($guild->invited as $a)
	$members[$a['rank']][] = array('id' => $a['id'], 'name' => $a['name'], 'nick' => 'Invited');

$i = 0;
while ($rank = current($members)){
	$i++;
	$rank_name = key($members);
	foreach ($rank as $member){
		if (!empty($member['nick'])) $nick = ' (<i>'.htmlspecialchars($member['nick']).'</i>)';
		else $nick = '';
		echo '<tr '.getStyle($i).'><td>'.htmlspecialchars($rank_name).'</td><td><a href="characters.php?player_id='.$member['id'].'">'.htmlspecialchars($member['name']).'</a> '.$nick.'</td></tr>';
		$rank_name = '';
	}
	next($members);
}
?>
</table>
<?php }
}?>
</div>
<div class="bot"></div>
</div>
<?php include('footer.inc.php');?>


PS: I'm using Nicaw_sql_v3.19 for TFS 0.3
 
Try this instead (make a backup of your original). This is the code for my guilds.php and it works. There's a slight difference in part of it towards the end, where it checks to see if there are members in the guild.

PHP:
<?php
include ("include.inc.php");
$ptitle="Guilds - $cfg[server_name]";
include ("header.inc.php");
$SQL = new SQL();
?>
<div id="content">
<div class="top">Guilds</div>
<div class="mid">
<form method="get" action="guilds.php"> 
<input type="text" name="guild_name"/> 
<input type="submit" value="Search"/> 
</form>
<hr style="margin-top: 5px; margin-bottom: 5px; "/>
<?php 
//-----------------------Guild list
if (!isset($_GET['guild_id']) && !isset($_GET['guild_name'])){
$query = 'SELECT guilds.id, guilds.name, nicaw_guild_info.description FROM guilds LEFT JOIN nicaw_guild_info ON guilds.id = nicaw_guild_info.id ORDER BY name ASC';
$SQL->myQuery($query);
if ($SQL->failed())
	throw new Exception('SQL query failed:<br/>'.$SQL->getError());
while ($a = $SQL->fetch_array()){
if (file_exists('guilds/'.$a['id'].'.gif')) 
	$img_path = 'guilds/'.$a['id'].'.gif';
else
	$img_path = 'ico/guild_default.gif';
?>
<table border="1" onclick="window.location.href='guilds.php?guild_id=<?php echo urlencode($a['id'])?>'" style="cursor: pointer; width: 100%;">
<tr><td style="width: 64px; height: 64px; padding: 10px;"><img src="<?php echo $img_path?>" alt="NO IMG" height="64" width="64"/></td>
<td style="vertical-align: top;">
<b><?php echo htmlspecialchars($a['name'])?></b><hr/>
<?php echo htmlspecialchars($a['description'])?>
</td></tr>
</table>
	
<?php }
}else{
//-------------------------Member list
$guild = new Guild();
if (!empty($_GET['guild_id']) && !$guild->load($_GET['guild_id']))
	echo 'Guild not found.';
elseif (!empty($_GET['guild_name']) && !$guild->find($_GET['guild_name']))
	echo 'Guild not found.';
else{
if (file_exists('guilds/'.$guild->getAttr('id').'.gif')) 
	$img_path = 'guilds/'.$guild->getAttr('id').'.gif';
else
	$img_path = 'ico/guild_default.gif';
?>
<table style="width: 100%"><tr><td style="width: 64px; height: 64px; padding: 10px;"><img src="<?php echo $img_path?>" alt="Guild IMG" height="64" width="64"/></td><td style="text-align: center">
<h1 style="display: inline"><?php echo htmlspecialchars($guild->getAttr('name'))?>
</h1></td><td style="width: 64px; height: 64px; padding: 10px;">
<img src="<?php echo $img_path?>" alt="Guild IMG" height="64" width="64"/></td></tr>
</table>
<p><?php echo htmlspecialchars($guild->getAttr('description'))?></p><hr/>
<ul class="task-menu" style="width: 200px;">
<li style="background-image: url(ico/book_previous.png);" onclick="self.window.location.href='guilds.php'">Back</li>
<?php 
if (!empty($_SESSION['account'])){
	$account = new Account();
	if (!$account->load($_SESSION['account'])) die('Cannot load account');
	$invited = false;
	$member = false;
	foreach ($account->players as $player){
		if ($guild->isInvited($player['id']))
			$invited = true;
		if ($guild->isMember($player['id']))
			$member = true;
	}
	if ($guild->getAttr('owner_acc') == $_SESSION['account']){?>
<li style="background-image: url(ico/user_go.png);" onclick="ajax('form','modules/guild_invite.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Invite Player</li>
<li style="background-image: url(ico/group_delete.png);" onclick="ajax('form','modules/guild_kick.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Kick Member</li>
<li style="background-image: url(ico/user_edit.png);" onclick="ajax('form','modules/guild_edit.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Edit Member</li>
<li style="background-image: url(ico/image_add.png);" onclick="ajax('form','modules/guild_image.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Upload Image</li>
<li style="background-image: url(ico/page_edit.png);" onclick="ajax('form','modules/guild_comments.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Edit Description</li>
<?php 	}
	if ($invited){?>
<li style="background-image: url(ico/user_red.png);" onclick="ajax('form','modules/guild_join.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Join Guild</li>
<?php 	}
	if ($member){?>
<li style="background-image: url(ico/user_delete.png);" onclick="ajax('form','modules/guild_leave.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Leave Guild</li>
<?php 	}?>
<li style="background-image: url(ico/resultset_previous.png);" onclick="self.window.location.href='login.php?logout&amp;redirect=account.php'">Logout</li>
<?php }else{?>
<li style="background-image: url(ico/resultset_next.png);" onclick="self.window.location.href='login.php?redirect=guilds.php'">Login</li>
<?php }?>
</ul><hr/>
<h2 style="display: inline">Guild Members</h2>
<table style="width: 100%">
<tr class="color0"><td style="width: 30%"><b>Rank</b></td><td style="width: 70%"><b>Name and Title</b></td></tr>
<?php 
foreach ($guild->members as $a)
	$members[$a['rank']][] = array('id' => $a['id'], 'name' => $a['name'], 'nick' => $a['nick']);
foreach ($guild->invited as $a)
	$members[$a['rank']][] = array('id' => $a['id'], 'name' => $a['name'], 'nick' => 'Invited');

$i = 0;
if (isset($members)){
	while ($rank = current($members)){
		$i++;
		$rank_name = key($members);
		foreach ($rank as $member){
			if (!empty($member['nick'])) $nick = ' (<i>'.htmlspecialchars($member['nick']).'</i>)';
			else $nick = '';
			echo '<tr '.getStyle($i).'><td>'.htmlspecialchars($rank_name).'</td><td><a href="characters.php?player_id='.$member['id'].'">'.htmlspecialchars($member['name']).'</a> '.$nick.'</td></tr>';
			$rank_name = '';
		}
		next($members);
	}
}else{
	echo 'Oh no! This guild has no members.';
}
?>
</table>
<?php }
}?>
</div>
<div class="bot"></div>
</div>
<?php include('footer.inc.php');?>
 
Try this instead (make a backup of your original). This is the code for my guilds.php and it works. There's a slight difference in part of it towards the end, where it checks to see if there are members in the guild.

PHP:
<?php
include ("include.inc.php");
$ptitle="Guilds - $cfg[server_name]";
include ("header.inc.php");
$SQL = new SQL();
?>
<div id="content">
<div class="top">Guilds</div>
<div class="mid">
<form method="get" action="guilds.php"> 
<input type="text" name="guild_name"/> 
<input type="submit" value="Search"/> 
</form>
<hr style="margin-top: 5px; margin-bottom: 5px; "/>
<?php 
//-----------------------Guild list
if (!isset($_GET['guild_id']) && !isset($_GET['guild_name'])){
$query = 'SELECT guilds.id, guilds.name, nicaw_guild_info.description FROM guilds LEFT JOIN nicaw_guild_info ON guilds.id = nicaw_guild_info.id ORDER BY name ASC';
$SQL->myQuery($query);
if ($SQL->failed())
	throw new Exception('SQL query failed:<br/>'.$SQL->getError());
while ($a = $SQL->fetch_array()){
if (file_exists('guilds/'.$a['id'].'.gif')) 
	$img_path = 'guilds/'.$a['id'].'.gif';
else
	$img_path = 'ico/guild_default.gif';
?>
<table border="1" onclick="window.location.href='guilds.php?guild_id=<?php echo urlencode($a['id'])?>'" style="cursor: pointer; width: 100%;">
<tr><td style="width: 64px; height: 64px; padding: 10px;"><img src="<?php echo $img_path?>" alt="NO IMG" height="64" width="64"/></td>
<td style="vertical-align: top;">
<b><?php echo htmlspecialchars($a['name'])?></b><hr/>
<?php echo htmlspecialchars($a['description'])?>
</td></tr>
</table>
	
<?php }
}else{
//-------------------------Member list
$guild = new Guild();
if (!empty($_GET['guild_id']) && !$guild->load($_GET['guild_id']))
	echo 'Guild not found.';
elseif (!empty($_GET['guild_name']) && !$guild->find($_GET['guild_name']))
	echo 'Guild not found.';
else{
if (file_exists('guilds/'.$guild->getAttr('id').'.gif')) 
	$img_path = 'guilds/'.$guild->getAttr('id').'.gif';
else
	$img_path = 'ico/guild_default.gif';
?>
<table style="width: 100%"><tr><td style="width: 64px; height: 64px; padding: 10px;"><img src="<?php echo $img_path?>" alt="Guild IMG" height="64" width="64"/></td><td style="text-align: center">
<h1 style="display: inline"><?php echo htmlspecialchars($guild->getAttr('name'))?>
</h1></td><td style="width: 64px; height: 64px; padding: 10px;">
<img src="<?php echo $img_path?>" alt="Guild IMG" height="64" width="64"/></td></tr>
</table>
<p><?php echo htmlspecialchars($guild->getAttr('description'))?></p><hr/>
<ul class="task-menu" style="width: 200px;">
<li style="background-image: url(ico/book_previous.png);" onclick="self.window.location.href='guilds.php'">Back</li>
<?php 
if (!empty($_SESSION['account'])){
	$account = new Account();
	if (!$account->load($_SESSION['account'])) die('Cannot load account');
	$invited = false;
	$member = false;
	foreach ($account->players as $player){
		if ($guild->isInvited($player['id']))
			$invited = true;
		if ($guild->isMember($player['id']))
			$member = true;
	}
	if ($guild->getAttr('owner_acc') == $_SESSION['account']){?>
<li style="background-image: url(ico/user_go.png);" onclick="ajax('form','modules/guild_invite.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Invite Player</li>
<li style="background-image: url(ico/group_delete.png);" onclick="ajax('form','modules/guild_kick.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Kick Member</li>
<li style="background-image: url(ico/user_edit.png);" onclick="ajax('form','modules/guild_edit.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Edit Member</li>
<li style="background-image: url(ico/image_add.png);" onclick="ajax('form','modules/guild_image.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Upload Image</li>
<li style="background-image: url(ico/page_edit.png);" onclick="ajax('form','modules/guild_comments.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Edit Description</li>
<?php 	}
	if ($invited){?>
<li style="background-image: url(ico/user_red.png);" onclick="ajax('form','modules/guild_join.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Join Guild</li>
<?php 	}
	if ($member){?>
<li style="background-image: url(ico/user_delete.png);" onclick="ajax('form','modules/guild_leave.php','guild_id=<?php echo $guild->getAttr('id')?>',true)">Leave Guild</li>
<?php 	}?>
<li style="background-image: url(ico/resultset_previous.png);" onclick="self.window.location.href='login.php?logout&amp;redirect=account.php'">Logout</li>
<?php }else{?>
<li style="background-image: url(ico/resultset_next.png);" onclick="self.window.location.href='login.php?redirect=guilds.php'">Login</li>
<?php }?>
</ul><hr/>
<h2 style="display: inline">Guild Members</h2>
<table style="width: 100%">
<tr class="color0"><td style="width: 30%"><b>Rank</b></td><td style="width: 70%"><b>Name and Title</b></td></tr>
<?php 
foreach ($guild->members as $a)
	$members[$a['rank']][] = array('id' => $a['id'], 'name' => $a['name'], 'nick' => $a['nick']);
foreach ($guild->invited as $a)
	$members[$a['rank']][] = array('id' => $a['id'], 'name' => $a['name'], 'nick' => 'Invited');

$i = 0;
if (isset($members)){
	while ($rank = current($members)){
		$i++;
		$rank_name = key($members);
		foreach ($rank as $member){
			if (!empty($member['nick'])) $nick = ' (<i>'.htmlspecialchars($member['nick']).'</i>)';
			else $nick = '';
			echo '<tr '.getStyle($i).'><td>'.htmlspecialchars($rank_name).'</td><td><a href="characters.php?player_id='.$member['id'].'">'.htmlspecialchars($member['name']).'</a> '.$nick.'</td></tr>';
			$rank_name = '';
		}
		next($members);
	}
}else{
	echo 'Oh no! This guild has no members.';
}
?>
</table>
<?php }
}?>
</div>
<div class="bot"></div>
</div>
<?php include('footer.inc.php');?>

Haha thx alot dude, it is working now, finally.

One more thing, if u dont mind:
There is a problem with my deathlist, when i watch the deathlist of people ingame with the talkaction '/deathlist Player'
it shows me the deathlist.
When i watch the deathlist on my homepage, it shows the same, but if a player gets killed by another player, the deathlist shows only the id of the killer, not the name :S

example:

30th October 2008 19:33:50 Killed at level 214 by 246

:/
 
Last edited:
The code in my characters.php file for showing deaths is like this
PHP:
	if ($cfg['show_deathlist']){
		$deaths = $player->getDeaths();
		if ($deaths !== false && !empty($deaths)){
		echo '<b>Deaths</b><br/>';
			foreach ($deaths as $death){
				$killer = new Player($death['killer']);
				if ($killer->exists())
					$name = '<a href="characters.php?char='.$death['killer'].'">'.$death['killer'].'</a>';
				else
					$name = $death['killer'];
				echo '<i>'.date("jS F Y H:i:s",$death['date']).'</i> Killed at level '.$death['level'].' by '.$name.'<br/>';
			}
		}
	}

I dont know if it's the same as yours because you're using the 0.3 version and I'm using the 0.2 version, so I'm not sure if the data is saved the same way or not. Could you post your characters.php ? If you do that I can take a look at how yours is pulling info from the DB and tell you what to change to get the players name instead of their ID
 
The code in my characters.php file for showing deaths is like this
PHP:
	if ($cfg['show_deathlist']){
		$deaths = $player->getDeaths();
		if ($deaths !== false && !empty($deaths)){
		echo '<b>Deaths</b><br/>';
			foreach ($deaths as $death){
				$killer = new Player($death['killer']);
				if ($killer->exists())
					$name = '<a href="characters.php?char='.$death['killer'].'">'.$death['killer'].'</a>';
				else
					$name = $death['killer'];
				echo '<i>'.date("jS F Y H:i:s",$death['date']).'</i> Killed at level '.$death['level'].' by '.$name.'<br/>';
			}
		}
	}

I dont know if it's the same as yours because you're using the 0.3 version and I'm using the 0.2 version, so I'm not sure if the data is saved the same way or not. Could you post your characters.php ? If you do that I can take a look at how yours is pulling info from the DB and tell you what to change to get the players name instead of their ID

There you go
PHP:
if ($cfg['show_deathlist']){
		$deaths = $player->getDeaths();
		if ($deaths !== false && !empty($deaths)){
		echo '<b>Deaths</b><br/>';
			foreach ($deaths as $death){
				$killer = new Player($death['killer']);
				if ($killer->exists())
					$name = '<a href="characters.php?char='.$death['killer'].'">'.$death['killer'].'</a>';
				else
					$name = $death['killer'];
				echo '<i>'.date("jS F Y H:i:s",$death['date']).'</i> Killed at level '.$death['level'].' by '.$name.'<br/>';
			}
		}
	}
}elseif (isset($_GET['player_id']) || isset($_GET['player_name'])) echo 'Player not found';
?>
Oh and btw, the guilds still aint work, i dont get any error msg or smth, it just doesnt work... u can create a guild, invite members and join the guild.. but after some time the guild is kinda wasted (ppl are not in the guild anymore, random ppl)
 
Last edited:
Your bit of code is exactly the same as mine. It seems as though the server is storing the ID of a player's character instead of the name.
 
Back
Top