collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Error creating a blob  (Read 2244 times)

0 Members and 1 Guest are viewing this topic.

Offline GBH

  • BeBot Hero
  • ******
  • Posts: 69
  • Karma: +0/-0
Error creating a blob
« 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

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Error creating a blob
« Reply #1 on: September 30, 2008, 04:36:17 am »
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++

Offline GBH

  • BeBot Hero
  • ******
  • Posts: 69
  • Karma: +0/-0
Re: Error creating a blob
« Reply #2 on: September 30, 2008, 11:16:37 am »
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

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Error creating a blob
« Reply #3 on: September 30, 2008, 03:00:37 pm »
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

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 690
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal