Array, object problem....

  • Follow


Hy guys...

I need some help...

In an object i have
$this->data as array of mysql query results(see example)

and a function in_multi_array() which isn't important.It just seraches for
$needle in a multidimensional array and returns bool

I have also these functions in an object

function &getID($needle)
 {
  foreach($this->data as $key=>$value)
      if(in_array($needle,$value))
    return $key;

 }

 function &getByValue($needle)
 {

   if($this->in_multi_array($needle,$this->data))
   {
    $id=$this->getID($needle);
    $array=$this->data[$id];
   }

   return $array;

 }

When you call $sample=$object->getByValue("something") and if "something" is
a result of a query (any field) then you get all the fields that belong to
that result in array

example:

DataBase:

id    |    name    |    lastname
--------------------------------------
1        John            Smith
2        Mark            Jones
3        George        Burchnall

query="SELECT id,name,lastname FROM people"
after everything....

$this->data will be:
 [data] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name] => John
                    [lastname] => Smith
                )

            [1] => Array
                (
                    [id] => 2
                    [name] => Mark
                    [lastname] => Jones
                )

            [2] => Array
                (
                    [id] => 3
                    [name] => George
                    [lastname] => Burchnall
                )

and when I call $sample=$object->getByValue("Mark")

$sample will be array (
                    [id] => 2
                    [name] => Mark
                    [lastname] => Jones
                    )

How can I get multiple results back if I have more than one "Mark" in DB

I would like then that $sample would be [0] for this Mark we just retreived
and [1] for second and so on so on...

I think I made my self clear :))

Thanx for the help....



0
Reply point5404 (24) 9/18/2003 3:30:34 PM

Huh....good news :)))

Just solved it :))))

I'm on the role......

YEEEEEEEE!!!!!!!!!

:)))

"point" <point@caanNOSPAMproduction.com> wrote in message
news:bkciva02vnc@enews4.newsguy.com...
> Hy guys...
>
> I need some help...
>
> In an object i have
> $this->data as array of mysql query results(see example)
>
> and a function in_multi_array() which isn't important.It just seraches for
> $needle in a multidimensional array and returns bool
>
> I have also these functions in an object
>
> function &getID($needle)
>  {
>   foreach($this->data as $key=>$value)
>       if(in_array($needle,$value))
>     return $key;
>
>  }
>
>  function &getByValue($needle)
>  {
>
>    if($this->in_multi_array($needle,$this->data))
>    {
>     $id=$this->getID($needle);
>     $array=$this->data[$id];
>    }
>
>    return $array;
>
>  }
>
> When you call $sample=$object->getByValue("something") and if "something"
is
> a result of a query (any field) then you get all the fields that belong to
> that result in array
>
> example:
>
> DataBase:
>
> id    |    name    |    lastname
> --------------------------------------
> 1        John            Smith
> 2        Mark            Jones
> 3        George        Burchnall
>
> query="SELECT id,name,lastname FROM people"
> after everything....
>
> $this->data will be:
>  [data] => Array
>         (
>             [0] => Array
>                 (
>                     [id] => 1
>                     [name] => John
>                     [lastname] => Smith
>                 )
>
>             [1] => Array
>                 (
>                     [id] => 2
>                     [name] => Mark
>                     [lastname] => Jones
>                 )
>
>             [2] => Array
>                 (
>                     [id] => 3
>                     [name] => George
>                     [lastname] => Burchnall
>                 )
>
> and when I call $sample=$object->getByValue("Mark")
>
> $sample will be array (
>                     [id] => 2
>                     [name] => Mark
>                     [lastname] => Jones
>                     )
>
> How can I get multiple results back if I have more than one "Mark" in DB
>
> I would like then that $sample would be [0] for this Mark we just
retreived
> and [1] for second and so on so on...
>
> I think I made my self clear :))
>
> Thanx for the help....
>
>
>


0
Reply point5404 (24) 9/18/2003 4:37:06 PM


"point" <point@caanNOSPAMproduction.com> wrote in message news:<bkcms103uu@enews4.newsguy.com>...
> Huh....good news :)))
> 
> Just solved it :))))
> 
> I'm on the role......
> 
> YEEEEEEEE!!!!!!!!!
> 
> :)))
> 

---------
Your solution would be helpful.
0
Reply russell4359 (19) 9/19/2003 12:30:17 PM

Oh sorry....

:))


here you go....


function &getID($needle)
 {
  foreach($this->data as $key=>$value)
      if(in_array($needle,$value))
        $keys[]=$key;
  return $keys;
 }

#################################################################
 function &getDataFor($needle)
 {
  if($needle==='all')
      return $this->data;
  else
   if($this->in_multi_array($needle,$this->data))
    if(is_array($id=$this->getID($needle)))
     foreach($id as $value)
      $array[]=$this->data[$value];
  return $array;
 }

#################################################################
    function &getSpecificDataFor($array_slice, $value)
    {
        foreach($this->data as $val)
        if(isset($val[$array_slice]))
            if($val[$array_slice]==$value)
                $array[]=$val;
        return $array;
    }

#################################################################

hope it helps....





"george" <russell@waiheke.co.nz> wrote in message
news:bcab4b38.0309190430.70f081d9@posting.google.com...
> "point" <point@caanNOSPAMproduction.com> wrote in message
news:<bkcms103uu@enews4.newsguy.com>...
> > Huh....good news :)))
> >
> > Just solved it :))))
> >
> > I'm on the role......
> >
> > YEEEEEEEE!!!!!!!!!
> >
> > :)))
> >
>
> ---------
> Your solution would be helpful.


0
Reply point9715 (15) 9/22/2003 10:32:45 PM

3 Replies
35 Views

(page loaded in 0.057 seconds)


Reply: