Array, object problem....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • point

    Array, object problem....

    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 multidimensiona l array and returns bool

    I have also these functions in an object

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

    }

    function &getByValue($ne edle)
    {

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

    return $array;

    }

    When you call $sample=$object->getByValue("so mething") 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,lastnam e 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("Ma rk")

    $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....



  • point

    #2
    Re: Array, object problem....

    Huh....good news :)))

    Just solved it :))))

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

    YEEEEEEEE!!!!!! !!!

    :)))

    "point" <point@caanNOSP AMproduction.co m> wrote in message
    news:bkciva02vn c@enews4.newsgu y.com...[color=blue]
    > 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 multidimensiona l array and returns bool
    >
    > I have also these functions in an object
    >
    > function &getID($need le)
    > {
    > foreach($this->data as $key=>$value)
    > if(in_array($ne edle,$value))
    > return $key;
    >
    > }
    >
    > function &getByValue($ne edle)
    > {
    >
    > if($this->in_multi_array ($needle,$this->data))
    > {
    > $id=$this->getID($needle) ;
    > $array=$this->data[$id];
    > }
    >
    > return $array;
    >
    > }
    >
    > When you call $sample=$object->getByValue("so mething") and if "something"[/color]
    is[color=blue]
    > 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,lastnam e 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("Ma rk")
    >
    > $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[/color]
    retreived[color=blue]
    > and [1] for second and so on so on...
    >
    > I think I made my self clear :))
    >
    > Thanx for the help....
    >
    >
    >[/color]


    Comment

    • george

      #3
      Re: Array, object problem....

      "point" <point@caanNOSP AMproduction.co m> wrote in message news:<bkcms103u u@enews4.newsgu y.com>...[color=blue]
      > Huh....good news :)))
      >
      > Just solved it :))))
      >
      > I'm on the role......
      >
      > YEEEEEEEE!!!!!! !!!
      >
      > :)))
      >[/color]

      ---------
      Your solution would be helpful.

      Comment

      • point

        #4
        Re: Array, object problem....

        Oh sorry....

        :))


        here you go....


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

        ############### ############### ############### ############### #####
        function &getDataFor($ne edle)
        {
        if($needle==='a ll')
        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 &getSpecificDat aFor($array_sli ce, $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@waihek e.co.nz> wrote in message
        news:bcab4b38.0 309190430.70f08 1d9@posting.goo gle.com...[color=blue]
        > "point" <point@caanNOSP AMproduction.co m> wrote in message[/color]
        news:<bkcms103u u@enews4.newsgu y.com>...[color=blue][color=green]
        > > Huh....good news :)))
        > >
        > > Just solved it :))))
        > >
        > > I'm on the role......
        > >
        > > YEEEEEEEE!!!!!! !!!
        > >
        > > :)))
        > >[/color]
        >
        > ---------
        > Your solution would be helpful.[/color]


        Comment

        Working...