Welcome Guest, Not a member yet? Register   Sign In
problem while using LIKE in my sql query
#1

[eluser]Unknown[/eluser]
Hello All,

I am new to CI and I am facing a problem while using LIKE in my sql query.

function - 1 (This function will return all the rows according to my query and assign to an array.)


$this->db->select('all_spirit_id', 'current_stock')->from('tbl_allspirits')->where('current_stock', '0');

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

foreach($query->result() as $row)

{

$namearray[] = $row;
}



Till now its good.

function - 2 (This function will check id form $namearray in another table and return the rows)


$this->db->select('*');

$this->db->from('mytable');


foreach($namearray as $cat)
{

$this->db->like('MyfieldName', $cat);

}
$result = $this->db->get()->result();


But this function is returnig all the rows(more than 100) and It should return the rows based on 'LIKE'(only 9 rows).

Getting below mentioned error with all the records.
-----------------------------------------------------------------------------
Severity: Warning

Message: mysql_real_escape_string() expects parameter 1 to be string, object given

Filename: mysql/mysql_driver.php

Line Number: 315
#2

[eluser]Otemu[/eluser]
add this to your controller

$this->output->enable_profiler(TRUE);

Then you can see the output of your queries and might be able to spot what the issue is
#3

[eluser]ZaLiTHkA[/eluser]
I haven't tried this myself, so I'm going blind here... But considering that this returns an array of objects:
Code:
$query->result()

So in this case, I suspect it might solve your current problem to use this instead:
Code:
$query->result_array()


Otherwise, after the first function has run, you could try echo a gettype() on the $namearray variable and see what it is at that point.
#4

[eluser]Unknown[/eluser]
Thank you so much guys. it helps me a lot.




Theme © iAndrew 2016 - Forum software by © MyBB