Home>

There is a Newroom model:

<
? PHP if (! Defined ('Basepath')) EXIT ('No Direct Script Access Allowed');
  Class Newroom_Model EXTENDS CI_MODEL {
      FUNCTION __CONSTRUCT () {
        Parent :: __ Construct ();
      }
      FUNCTION GET () {
        $ Data= Array ();
        //First request
        $ Query= $ this->
DB->
Query ("Call Gethometypes ()");
        $ res= $ query->
result_array ();
        For ($ i= 0; $ i <
Count ($ Res); $ i ++) {
          $ data ['home_types'] [$ i] ['type_id']= $ res [$ i] ['TypeID'];
          $ data ['home_types'] [$ i] ['type_name']= $ res [$ i] ['typeName'];
        }
        //second request
        $ Query2= $ this->
DB->
Query ("Call GetroomTypes ()");
        $ res1= $ Query2->
result_array ();
        For ($ i= 0; $ i <
Count ($ RES1); $ i ++) {
        $ Data ['ROOM_TYPES'] [$ i] ['type_id']= $ res1 [$ i] ['typeid'];
        $ Data ['ROOM_TYPES'] [$ i] ['type_name']= $ res1 [$ i] ['typeName'];
        }
        //Print_R ($ Data);
        Return $ Data;
}
}

If you execute one of 2 requests in the model -everything works, if together -does not return anything.

  • Answer # 1

    something you have a terrible thing here)) if you understand correctly, you need to pull the dependence of two tables from the database

    //
        Public Function Info_user ($ ID)
        {
            $ this->
    DB->
    SELECT ('Users. *, Cities.name as city');
            $ this->
    DB->
    from ('users');
            $ this->
    DB->
    join ('Cities', 'users.city_id= Cities.id', 'Inner');
            $ this->
    DB->
    Where ('Users.ID', $ ID);
            $ sqldata= $ this->
    DB->
    get ();
            Return $ sqldata->
    result_array ();
        }
    

    Here with Join in one array is going to the desired infa in this case all info about user and the city name

    @ igorianru, what attitude does your answer to my question?

    Denis Makarenko2021-04-07 18:15:46