A country, State, and city name display the correct from the first table but also display the same details of the second table The 2019 Stack Overflow Developer Survey Results Are InDisplaying name from ID of lookup tables - design QPhp SQL query check (count ?) if they are listings depending of cities, states and countriesfetch and display values from multiple mysql tables using phpSort MySQL table recordsBest way to split a table in Parent-Child to avoid duplicated information in MySQLDisplaying Data From 4 (Four) Tables in MysqlBetter approach to use Country-State-City moduleSearching a user by country city state districtmongodb - $lookup not working with $projectHow to join country state and city in a single query?

Loose spokes after only a few rides

Origin of "cooter" meaning "vagina"

What is the accessibility of a package's `Private` context variables?

For what reasons would an animal species NOT cross a *horizontal* land bridge?

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

A poker game description that does not feel gimmicky

How technical should a Scrum Master be to effectively remove impediments?

Where to refill my bottle in India?

What did it mean to "align" a radio?

The difference between dialogue marks

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

If a Druid sees an animal’s corpse, can they Wild Shape into that animal?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Are there incongruent pythagorean triangles with the same perimeter and same area?

Does the shape of a die affect the probability of a number being rolled?

Reference request: Oldest number theory books with (unsolved) exercises?

Is flight data recorder erased after every flight?

Why is the maximum length of OpenWrt’s root password 8 characters?

Delete all lines which don't have n characters before delimiter

Why isn't airport relocation done gradually?

Is three citations per paragraph excessive for undergraduate research paper?

Am I thawing this London Broil safely?

How to manage monthly salary

Identify boardgame from Big movie



A country, State, and city name display the correct from the first table but also display the same details of the second table



The 2019 Stack Overflow Developer Survey Results Are InDisplaying name from ID of lookup tables - design QPhp SQL query check (count ?) if they are listings depending of cities, states and countriesfetch and display values from multiple mysql tables using phpSort MySQL table recordsBest way to split a table in Parent-Child to avoid duplicated information in MySQLDisplaying Data From 4 (Four) Tables in MysqlBetter approach to use Country-State-City moduleSearching a user by country city state districtmongodb - $lookup not working with $projectHow to join country state and city in a single query?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have tbl_customer, shipping, countries, state and city tables and columns are



tbl_customer



cust_id | Name | Email |b_address | b_country | b_State | b_city 
1 | zxxzc | zxz@gmail.com |asdasasdsa | 231 | 3936 | 45645
2 | ergtf | okh@gmail.com |hghggjhghg | 231 | 3948 | 45497
3 | oiuyt | ert@gmail.com |mkjhgfdddd | 231 | 3927 | 43472


shipping



s_id | s_address | s_country | s_State | s_city | cust_id
1 | asdasasdsa | 231 | 3934 | 44173 | 1
2 | oiuytrjhhg | 13 | 273 | 6815 | 3


Now I have to fetch country, state and city name from both the tables.
So I tried joins like



$this->db->select("*")
$this->db->from('tbl_customer');
$this->db->join('shipping', 'tbl_customer.cust_id=shipping.cust_id', 'LEFT');
$this->db->join('countries', 'countries.id=tbl_customer.b_country OR countries.id=shipping.s_country');
$this->db->join('states', 'states.id=tbl_customer.b_State OR states.id=shipping.s_State');
$this->db->join('city', 'city.id=tbl_customer.b_city OR city.id=shipping.s_city');

$query = $this->db->get();
$result = $query->result();
if($result)

return $result;

else

return 0;



Controller



$list_1=$this->Reports_model->get_details(); 
foreach($list_1 as $row)

/*customer table*/
$countryname=$row->country_name;
$state_name=$row->state_name;
$cities_name=$row->cities_name;

/*shipping table*/
$countryname_s=$row->country_name;
$state_name_s=$row->state_name;
$cities_name_s=$row->cities_name;




but the issue is, I am getting the same country name, state name, and city name. I mean tbl_customer details are displaying correct but shipping details are also displaying the same details.



I think I have to use an alias name to display the shipping details.










share|improve this question






























    0















    I have tbl_customer, shipping, countries, state and city tables and columns are



    tbl_customer



    cust_id | Name | Email |b_address | b_country | b_State | b_city 
    1 | zxxzc | zxz@gmail.com |asdasasdsa | 231 | 3936 | 45645
    2 | ergtf | okh@gmail.com |hghggjhghg | 231 | 3948 | 45497
    3 | oiuyt | ert@gmail.com |mkjhgfdddd | 231 | 3927 | 43472


    shipping



    s_id | s_address | s_country | s_State | s_city | cust_id
    1 | asdasasdsa | 231 | 3934 | 44173 | 1
    2 | oiuytrjhhg | 13 | 273 | 6815 | 3


    Now I have to fetch country, state and city name from both the tables.
    So I tried joins like



    $this->db->select("*")
    $this->db->from('tbl_customer');
    $this->db->join('shipping', 'tbl_customer.cust_id=shipping.cust_id', 'LEFT');
    $this->db->join('countries', 'countries.id=tbl_customer.b_country OR countries.id=shipping.s_country');
    $this->db->join('states', 'states.id=tbl_customer.b_State OR states.id=shipping.s_State');
    $this->db->join('city', 'city.id=tbl_customer.b_city OR city.id=shipping.s_city');

    $query = $this->db->get();
    $result = $query->result();
    if($result)

    return $result;

    else

    return 0;



    Controller



    $list_1=$this->Reports_model->get_details(); 
    foreach($list_1 as $row)

    /*customer table*/
    $countryname=$row->country_name;
    $state_name=$row->state_name;
    $cities_name=$row->cities_name;

    /*shipping table*/
    $countryname_s=$row->country_name;
    $state_name_s=$row->state_name;
    $cities_name_s=$row->cities_name;




    but the issue is, I am getting the same country name, state name, and city name. I mean tbl_customer details are displaying correct but shipping details are also displaying the same details.



    I think I have to use an alias name to display the shipping details.










    share|improve this question


























      0












      0








      0








      I have tbl_customer, shipping, countries, state and city tables and columns are



      tbl_customer



      cust_id | Name | Email |b_address | b_country | b_State | b_city 
      1 | zxxzc | zxz@gmail.com |asdasasdsa | 231 | 3936 | 45645
      2 | ergtf | okh@gmail.com |hghggjhghg | 231 | 3948 | 45497
      3 | oiuyt | ert@gmail.com |mkjhgfdddd | 231 | 3927 | 43472


      shipping



      s_id | s_address | s_country | s_State | s_city | cust_id
      1 | asdasasdsa | 231 | 3934 | 44173 | 1
      2 | oiuytrjhhg | 13 | 273 | 6815 | 3


      Now I have to fetch country, state and city name from both the tables.
      So I tried joins like



      $this->db->select("*")
      $this->db->from('tbl_customer');
      $this->db->join('shipping', 'tbl_customer.cust_id=shipping.cust_id', 'LEFT');
      $this->db->join('countries', 'countries.id=tbl_customer.b_country OR countries.id=shipping.s_country');
      $this->db->join('states', 'states.id=tbl_customer.b_State OR states.id=shipping.s_State');
      $this->db->join('city', 'city.id=tbl_customer.b_city OR city.id=shipping.s_city');

      $query = $this->db->get();
      $result = $query->result();
      if($result)

      return $result;

      else

      return 0;



      Controller



      $list_1=$this->Reports_model->get_details(); 
      foreach($list_1 as $row)

      /*customer table*/
      $countryname=$row->country_name;
      $state_name=$row->state_name;
      $cities_name=$row->cities_name;

      /*shipping table*/
      $countryname_s=$row->country_name;
      $state_name_s=$row->state_name;
      $cities_name_s=$row->cities_name;




      but the issue is, I am getting the same country name, state name, and city name. I mean tbl_customer details are displaying correct but shipping details are also displaying the same details.



      I think I have to use an alias name to display the shipping details.










      share|improve this question
















      I have tbl_customer, shipping, countries, state and city tables and columns are



      tbl_customer



      cust_id | Name | Email |b_address | b_country | b_State | b_city 
      1 | zxxzc | zxz@gmail.com |asdasasdsa | 231 | 3936 | 45645
      2 | ergtf | okh@gmail.com |hghggjhghg | 231 | 3948 | 45497
      3 | oiuyt | ert@gmail.com |mkjhgfdddd | 231 | 3927 | 43472


      shipping



      s_id | s_address | s_country | s_State | s_city | cust_id
      1 | asdasasdsa | 231 | 3934 | 44173 | 1
      2 | oiuytrjhhg | 13 | 273 | 6815 | 3


      Now I have to fetch country, state and city name from both the tables.
      So I tried joins like



      $this->db->select("*")
      $this->db->from('tbl_customer');
      $this->db->join('shipping', 'tbl_customer.cust_id=shipping.cust_id', 'LEFT');
      $this->db->join('countries', 'countries.id=tbl_customer.b_country OR countries.id=shipping.s_country');
      $this->db->join('states', 'states.id=tbl_customer.b_State OR states.id=shipping.s_State');
      $this->db->join('city', 'city.id=tbl_customer.b_city OR city.id=shipping.s_city');

      $query = $this->db->get();
      $result = $query->result();
      if($result)

      return $result;

      else

      return 0;



      Controller



      $list_1=$this->Reports_model->get_details(); 
      foreach($list_1 as $row)

      /*customer table*/
      $countryname=$row->country_name;
      $state_name=$row->state_name;
      $cities_name=$row->cities_name;

      /*shipping table*/
      $countryname_s=$row->country_name;
      $state_name_s=$row->state_name;
      $cities_name_s=$row->cities_name;




      but the issue is, I am getting the same country name, state name, and city name. I mean tbl_customer details are displaying correct but shipping details are also displaying the same details.



      I think I have to use an alias name to display the shipping details.







      php mysql codeigniter-3






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 7:31







      questionbank

















      asked Mar 22 at 3:47









      questionbankquestionbank

      3917




      3917






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Shipping and customer tables column names are different.



           foreach($list_1 as $row)

          /*customer table*/
          $countryname=$row->b_country;
          $state_name=$row->b_state;
          $cities_name=$row->b_city;

          /*shipping table*/
          $countryname_s=$row->s_country;
          $state_name_s=$row->s_state;
          $cities_name_s=$row->s_city;




          To show country, state and city name your select query should be something like below.



          $this->db->select("c.*, c1.name as country_name, c2.name as shipping_country, s1.name as state_name, s2.name as shipping_state, ci1.name as city_name, ci2.name as shipping_city")
          $this->db->from('tbl_customer c');
          $this->db->join('shipping s', 'c.cust_id=s.cust_id', 'LEFT');
          $this->db->join('countries c1', 'c1.id=c.b_country');
          $this->db->join('countries c2', 'c2.id=s.s_country');
          $this->db->join('states s1', 's1.id=c.b_State');
          $this->db->join('states s2', 's2.id=s.s_State');
          $this->db->join('city ci1', 'ci1.id=c.b_city');
          $this->db->join('city ci2', 'ci2.id=s.s_city');





          share|improve this answer

























          • Yes, columns name are different but Column name will display the only number. I have to display the name of the country which id is 231.

            – questionbank
            Mar 22 at 9:38











          • Let me try your answer, Give me some time to check

            – questionbank
            Mar 22 at 10:06











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292603%2fa-country-state-and-city-name-display-the-correct-from-the-first-table-but-als%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Shipping and customer tables column names are different.



           foreach($list_1 as $row)

          /*customer table*/
          $countryname=$row->b_country;
          $state_name=$row->b_state;
          $cities_name=$row->b_city;

          /*shipping table*/
          $countryname_s=$row->s_country;
          $state_name_s=$row->s_state;
          $cities_name_s=$row->s_city;




          To show country, state and city name your select query should be something like below.



          $this->db->select("c.*, c1.name as country_name, c2.name as shipping_country, s1.name as state_name, s2.name as shipping_state, ci1.name as city_name, ci2.name as shipping_city")
          $this->db->from('tbl_customer c');
          $this->db->join('shipping s', 'c.cust_id=s.cust_id', 'LEFT');
          $this->db->join('countries c1', 'c1.id=c.b_country');
          $this->db->join('countries c2', 'c2.id=s.s_country');
          $this->db->join('states s1', 's1.id=c.b_State');
          $this->db->join('states s2', 's2.id=s.s_State');
          $this->db->join('city ci1', 'ci1.id=c.b_city');
          $this->db->join('city ci2', 'ci2.id=s.s_city');





          share|improve this answer

























          • Yes, columns name are different but Column name will display the only number. I have to display the name of the country which id is 231.

            – questionbank
            Mar 22 at 9:38











          • Let me try your answer, Give me some time to check

            – questionbank
            Mar 22 at 10:06















          0














          Shipping and customer tables column names are different.



           foreach($list_1 as $row)

          /*customer table*/
          $countryname=$row->b_country;
          $state_name=$row->b_state;
          $cities_name=$row->b_city;

          /*shipping table*/
          $countryname_s=$row->s_country;
          $state_name_s=$row->s_state;
          $cities_name_s=$row->s_city;




          To show country, state and city name your select query should be something like below.



          $this->db->select("c.*, c1.name as country_name, c2.name as shipping_country, s1.name as state_name, s2.name as shipping_state, ci1.name as city_name, ci2.name as shipping_city")
          $this->db->from('tbl_customer c');
          $this->db->join('shipping s', 'c.cust_id=s.cust_id', 'LEFT');
          $this->db->join('countries c1', 'c1.id=c.b_country');
          $this->db->join('countries c2', 'c2.id=s.s_country');
          $this->db->join('states s1', 's1.id=c.b_State');
          $this->db->join('states s2', 's2.id=s.s_State');
          $this->db->join('city ci1', 'ci1.id=c.b_city');
          $this->db->join('city ci2', 'ci2.id=s.s_city');





          share|improve this answer

























          • Yes, columns name are different but Column name will display the only number. I have to display the name of the country which id is 231.

            – questionbank
            Mar 22 at 9:38











          • Let me try your answer, Give me some time to check

            – questionbank
            Mar 22 at 10:06













          0












          0








          0







          Shipping and customer tables column names are different.



           foreach($list_1 as $row)

          /*customer table*/
          $countryname=$row->b_country;
          $state_name=$row->b_state;
          $cities_name=$row->b_city;

          /*shipping table*/
          $countryname_s=$row->s_country;
          $state_name_s=$row->s_state;
          $cities_name_s=$row->s_city;




          To show country, state and city name your select query should be something like below.



          $this->db->select("c.*, c1.name as country_name, c2.name as shipping_country, s1.name as state_name, s2.name as shipping_state, ci1.name as city_name, ci2.name as shipping_city")
          $this->db->from('tbl_customer c');
          $this->db->join('shipping s', 'c.cust_id=s.cust_id', 'LEFT');
          $this->db->join('countries c1', 'c1.id=c.b_country');
          $this->db->join('countries c2', 'c2.id=s.s_country');
          $this->db->join('states s1', 's1.id=c.b_State');
          $this->db->join('states s2', 's2.id=s.s_State');
          $this->db->join('city ci1', 'ci1.id=c.b_city');
          $this->db->join('city ci2', 'ci2.id=s.s_city');





          share|improve this answer















          Shipping and customer tables column names are different.



           foreach($list_1 as $row)

          /*customer table*/
          $countryname=$row->b_country;
          $state_name=$row->b_state;
          $cities_name=$row->b_city;

          /*shipping table*/
          $countryname_s=$row->s_country;
          $state_name_s=$row->s_state;
          $cities_name_s=$row->s_city;




          To show country, state and city name your select query should be something like below.



          $this->db->select("c.*, c1.name as country_name, c2.name as shipping_country, s1.name as state_name, s2.name as shipping_state, ci1.name as city_name, ci2.name as shipping_city")
          $this->db->from('tbl_customer c');
          $this->db->join('shipping s', 'c.cust_id=s.cust_id', 'LEFT');
          $this->db->join('countries c1', 'c1.id=c.b_country');
          $this->db->join('countries c2', 'c2.id=s.s_country');
          $this->db->join('states s1', 's1.id=c.b_State');
          $this->db->join('states s2', 's2.id=s.s_State');
          $this->db->join('city ci1', 'ci1.id=c.b_city');
          $this->db->join('city ci2', 'ci2.id=s.s_city');






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 22 at 10:04

























          answered Mar 22 at 9:30









          Sangita KendreSangita Kendre

          6516




          6516












          • Yes, columns name are different but Column name will display the only number. I have to display the name of the country which id is 231.

            – questionbank
            Mar 22 at 9:38











          • Let me try your answer, Give me some time to check

            – questionbank
            Mar 22 at 10:06

















          • Yes, columns name are different but Column name will display the only number. I have to display the name of the country which id is 231.

            – questionbank
            Mar 22 at 9:38











          • Let me try your answer, Give me some time to check

            – questionbank
            Mar 22 at 10:06
















          Yes, columns name are different but Column name will display the only number. I have to display the name of the country which id is 231.

          – questionbank
          Mar 22 at 9:38





          Yes, columns name are different but Column name will display the only number. I have to display the name of the country which id is 231.

          – questionbank
          Mar 22 at 9:38













          Let me try your answer, Give me some time to check

          – questionbank
          Mar 22 at 10:06





          Let me try your answer, Give me some time to check

          – questionbank
          Mar 22 at 10:06



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292603%2fa-country-state-and-city-name-display-the-correct-from-the-first-table-but-als%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript