BeBot - An Anarchy Online and Age Of Conan chat automaton
Archive => Age of Conan Archive => BeBot Hyborian support => Topic started by: GBH on September 30, 2008, 03:08:42 am
-
Hi,
I'm working an a members information module and I'm a little stuck. Note I'm fairly clueless at PHP ;)
So far I have the following function
function membersinfo()
{
$blob = "";
$count = 0;
$guild ="";
$result1 = $this -> bot -> db -> select("SELECT nickname, last_seen FROM #___users WHERE user_level = " . MEMBER . " ORDER BY nickname ASC");
$result2 = $this -> bot -> db -> select("SELECT alt FROM #___alts ORDER BY main ASC");
$result3 = $this -> bot -> db -> select("SELECT COUNT(DISTINCT main) FROM #___alts");
if (!empty($result1))
{
$inside = "##blob_title##:::: Guild Member Stats ::::##end##\n\n";
foreach ($result1 as $val)
{
$count++;
}
$inside .= "There are " .$count. " members in ".$guild."\n";
}
if (!empty($result2))
{
$count2=0;
foreach ($result2 as $val)
{
$count2++;
}
$inside .= "There are " .$count2. " alts in ".$guild."\n";
}
if (!empty($result3))
{
$inside .= "There are " .$result3. " mains in ".$guild."\n";
}
$blob = " :: " . $this -> bot -> core("tools") -> make_blob("click to view", $inside);
return $blob;
}
Now the first 2 return the right results but the last one doesn't.
So far I've tried
Pulling all the names of mains from the db then trying to array_unique them - that showed the value as the same as alts (meaning it wasn't stripping out the duplicates)
Pulling it in as shown and displaying the result directly - This results in the blob having "Array" in place of the numeric value
Pulling them in as shown and using an array call to display all values in the array - This results in the blob having "Array" in place of the numeric value
Entering $result3 = 55 and this "works" in the sense it returns the value 55 in the blob
The values seems to go from 0 to 1 to "Array" to the same value as the number of alts.
I'm sure it's something very obvious that highlights my lack of PHP skills but after 4 hours working on it I'm losing the will to live.
Someone care to put me out of my misery and explain why it doesn't work the way I think it does and tell me how it does work?
Thanks
Buff
-
yes it returns an array
you have to use $result3[0] or $result3[0][0]
btw an easy way to count is
$count = count($result)
instead of useing foreach and $count++
-
yes it returns an array
you have to use $result3[0] or $result3[0][0]
btw an easy way to count is
$count = count($result)
instead of useing foreach and $count++
HMmmmmmmmm
Thanks for the reply.
I tried
if (!empty($result3))
{
$inside .= "There are " .$result3[0]. " mains in ".$guild."\n";
}
and
if (!empty($result3))
{
$mains=$result3[0];
$inside .= "There are " .$mains. " mains in ".$guild."\n";
}
and variations of the same with
if (!empty($result3[0]))
The one that eventually seemed to work was
if (!empty($result3))
{
$mains=$result3[0];
$inside .= "There are " .$mains[0]. " mains in ".$guild."\n";
}
Now the question for my PHP skills development is why?
Why does that work where plugging $result3[0] in directly doesn't? Aren't I, by doing that, just simply creating another identical array with a different name?
Cheers for the other pointers though - thats what happens when you steal other peoples code only to find they're fumbling in the dark just like you are ;)
Buff
-
if that works then the correct thing was $result3[0][0]
i did say it could be that 1
basicly mysql returns data in an array
the 1st[0] was for the row
the 2nd[0] was for the column