Welcome Guest, Not a member yet? Register   Sign In
help me write this mysql query in codeigniter
#1

(This post was last modified: 11-11-2019, 08:00 PM by acebay.)

Hi All,

I need help on writing this MySQL query in CodeIgniter

   
Code:
SELECT *, ABS( post_code - 2015 ) AS distance FROM list_data WHERE business_name LIKE '%cash%' ESCAPE '!' ORDER BY distance LIMIT 6


2015 and '%cash%' is coming from input fields

so far I have written it like this but not working

 
PHP Code:
public function searchListing($data$location) {
    $this->db->select('(SELECT *, ABS(`post_code`-' $location' AS distance FROM `list_data` ORDER BY distance)'FALSE);
    $this->db->like('business_names'$data);
    $query $this->db->get();
    return $query->result();
    


I've attached images of the table, first image is showing all data in the table, the second image is the query that I want to achieve in codeigniter



Can anyone help me? Thanks

Attached Files Thumbnail(s)
       
Reply


Messages In This Thread
help me write this mysql query in codeigniter - by acebay - 11-11-2019, 06:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB