How can I speed up the database process?

前端 未结 4 1849
暖寄归人
暖寄归人 2021-01-24 03:34

I have a MySQL database that has over 9000 rows with 10 fields. It was imported from an Excel file so it\'s all in one table.

When I run the query, which has already na

4条回答
  •  鱼传尺愫
    2021-01-24 03:53

    Are you running your queries inside a loop of some sort?

    Agree with pagination answers, use limits and offsets. If you run 10per page thats 700 queries. I would use codeigniter's pagination lib as follows.

    $route['controller/(:num)'] = 'controller/index/$1';
    

    -

    public function index($offset=0)
    {
    
       //set a limit of 10 per result
       $limit = 10;
    
       //query the database
       $q = "SELECT * FROM {table_name} LIMIT={limit} OFFSET={offset} ORDER BY {date} desc";
    
       //count the results
       $count = count({query results});
    
       //setup pagination config
       $config = array(
            'base_url' => site_url('controller/'),
            'total_rows' => $count,
            'per_page' => $limit,
            'uri_segment' => 2
       );
    
       //init the pagigination
       $this->pagination->initialize($config);
    
       //load the view and pagination data
        $this->load->view('link_to_template', array(
                'pagination'  =>  $this->pagination->create_links(),
                'results'  =>  {query results}
        ));
    
    } 
    

提交回复
热议问题