Reputation: 455
i am using below query ,its converting all things to string
$idsv =$_GET['ids'];
$ids=$db->value($idsv, 'string');
$search = $this->Search->query("select * from colleges where college_id!='' and college_id in ($ids) ");
above code is working ok for single string , but if $idsv =1,2,3,4 its giving result only for 1
Upvotes: 1
Views: 44
Reputation: 72289
You need to it like below:-
$idsv =$_GET['ids'];
$ids=$db->value($idsv, 'string');
$ids = "'".implode("','",explode(',',$ids))."'";
$search = $this->Search->query("select * from colleges where college_id!='' and college_id in ($ids) ")
output:- https://eval.in/716469
Note:- IN
query works perfectly for ('1','2','3',...)
but takes only first one when comes like this:-('1,2,3,4')
.
And that's the exact reason why it's failing in your case.
What you shown in comment,do like below:-
$idsv =$_GET['ids'];
$ids=$db->value($idsv, 'string');
$ids = implode("','",explode(',',$ids));
$search = $this->Search->query("select * from colleges where college_id!='' and college_id in ($ids) ")
Upvotes: 1