0

Base on this question finally can show result of query in phppgAdmin faster then before. Only add LIMIT 1 after PostgreSQL CONCAT function make different about 5s which is from 7s to 2s.

This is my short sql:

$sql = "select tb1.*, 
(select name_code from master_code tb2 where tb2.code like CONCAT('%', tb1.code, '%') LIMIT 1) as master_code_name
from city tb1 where tb1.location_id like 'blablabla%'";

I use this script to show city based on location_id. One column of city contain code from master_code. Actually, I just want to try to show the name of that column. But when I try to load using Model and Controller, showing 500 Internal Server Error in console.

This is code in Model:

  public function select_by_location(){

    $sql = "select tb1.*, (select name_code from master_code tb2 where tb2.code like CONCAT('%', tb1.code, '%') LIMIT 1) as master_code_name from city tb1 where tb1.location_id like 'blablabla%'";

        $data = $this->db->query($sql);

        return $data->result_array();
    }

This is the Controller:

 public function show() {
     $data['dataCity'] = $this->M_city->select_by_location();
     $this->load->view('city/list_data', $data);
 }

Ajax:

  function showCityAjax() {
    $.get('<?php echo base_url('City_controller/show'); ?>', function(data) {
        $('#data-city').html(data);
        refresh();
    });
  }

Show result in:

<div id="data-city"></div>

How to resolve this? Or is there another way to do it more efficiently. Thanks.

Ugy Astro
  • 357
  • 3
  • 6
  • 16

0 Answers0