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

(11-12-2019, 03:49 PM)acebay Wrote:
(11-12-2019, 09:27 AM)Piotr Wrote:
PHP Code:
Easiest way:

$q $this->db->query("SELECT *, ABS( post_code - 2015 ) AS distance FROM list_data WHERE business_name LIKE '%cash%' ESCAPE '!' ORDER BY distance LIMIT 6");

print_r($q->result()); 

Hi, @Piotr thank you for your reply, you forgot that 2015 and '%cash%' is coming from input fields so you can treat it as a string. Please look at the solution from @Chivinsdev, his solution is correct.

Note the code can still work but he forgot to arrange it well for you to understand it.
That is

PHP Code:
$q $this->db->query("SELECT *, ABS(post_code - ".$location.") AS distance FROM list_data WHERE business_name LIKE '%".$data."%' ESCAPE '!' ORDER BY distance LIMIT 6")->result();

print_r($q); 

I hope it will also work as expected
Reply


Messages In This Thread
RE: help me write this mysql query in codeigniter - by Chivinsdev - 11-18-2019, 07:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB