PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] comparing column in database to values in array of objects

 March 15, 2022     codeigniter, filter, php, where-clause     No comments   

Issue

i have this array of objects as a result of the following code:

$varIds = $this->user_model->get_var_id(...);

it produces something like this :

[
    {var_id: "141"}
    {var_id: "143"}
    {var_id: "146"}
    {var_id: "149"}
]

next step, sending this array to model like this:

$this->user_model->get_item_options_values_filter(...,$varIds);

next, filtering like this:

$this->db->where_in('items_options_value.var_id',$varIds);

i want to filter the rows based on the values in the $varIds array of objects, but this does not work as the where_in clause gives error array to string conversion, so how to compare the value of the var_id column with the values in $varIds?


Solution

i had to first convert array of objects into array of values like this :

     $names = array();
     foreach($varIds as $v){
         array_push($names,$v['var_id']);
     }

then :

     $this->db->where_in('items_options_value.var_id',$names);


Answered By - Aasem Shoshari
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing