![]() |
I feel stupid asking this question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: I feel stupid asking this question (/showthread.php?tid=22119) Pages:
1
2
|
I feel stupid asking this question - El Forum - 08-30-2009 [eluser]tim1965[/eluser] But here goes I am running a query on my db that may return one or more rows, but only one column "object_id". This correctly generates an array Quote:Array ( [0] => Array ( [object_id] => 1 ) ) Quote:But (and heres the stipid part) i need to flatten this to look like Quote:$names = array('Frank', 'Todd', 'James'); Quote:Any help appreciated I feel stupid asking this question - El Forum - 08-30-2009 [eluser]alboyd[/eluser] W. T. F. But having said that - please post your query as this might explain EVERYTHING EDIT: Oh hang on - having read this a fourth time I think I know what you are saying... So Object_Id = Frank, Tim, Bill, Fred etc right? Run your query.. assuming it is saved to $objects Code: foreach ($objects->result() as $object) I feel stupid asking this question - El Forum - 08-30-2009 [eluser]tim1965[/eluser] Hi And thnx for replying and apologies for the question. I have been grappling with a query all day.What i am trying to do is set an array values for $names = array('Frank', 'Todd', 'James'); $this->db->where_not_in('username', $names); I tried your example and got Fatal error: Call to a member function result() on a non-object I feel stupid asking this question - El Forum - 08-30-2009 [eluser]alboyd[/eluser] Hey mate, No offense and it might just be that I am tired and (have had a few) but I don't understand what you want. Could you please start from the beginning and explain your question? I would love to help you (if I can) but I really need to understand what you are talking about first. Tell me what is your controller code, your model... I feel stupid asking this question - El Forum - 08-30-2009 [eluser]tim1965[/eluser] Sry if i am not clear (minus the beers i am in the same position as you, although i could murder one right now). Ok from the top. I am running two queries for a search page. The first generates some variable ids for the second query. On the second query i am trying to populate a where_not_in. So my first query returns an array as above in my first post. I want to use this populate the where_not_in for my second query. So the manual says do this Quote:$names = array('Frank', 'Todd', 'James'); $this->db->where_not_in('username', $names); // Produces: WHERE username NOT IN ('Frank', 'Todd', 'James') Quote:However i cannot work out how to make my array thre same as the manual Relevant part of my query is $this->db->where_not_in('master_property_reference.property_id', $v); //$this->db->where_not_in('username', $names); $query = $this->db->get(); if($query->num_rows() >0) { $row=$query->result_array(); return $row; } with $v currently only being accessed by explicitly setting it to $v=$r['0']['object_id']; Obviously that wont work with more than one element. My controller is $result = $this->M_search_v1->check_dates(); So all i am trying to do is get the result of my first query to look like the manual says so thati can pass this->db->where_not_in an array to populate my second query. I hope this is clear. I feel stupid asking this question - El Forum - 08-30-2009 [eluser]alboyd[/eluser] I don't know why my snippet didn't help with this? Run your first query - assign results to $query_results Code: foreach ($query_results->result() as $row) { Run your second query and use $not_in... I don't use activerecord myself although for once, with this example, I can see where it would be pretty useful! But nevertheless perhaps your syntax for the not_in db class function is wrong - i don't know cause I don't use it. Sorry I can't help more mate.. I'll look at this in the daylight tomorrow and perhaps see where I have gone wrong! I feel stupid asking this question - El Forum - 08-30-2009 [eluser]tim1965[/eluser] Ok thnx i will run thru your suggestion later and appreciate your help, i know i am probably doing something stupid, but cannot get it. Thnx again. I feel stupid asking this question - El Forum - 08-30-2009 [eluser]tim1965[/eluser] Bingo solved Problem was at my end. I had some old code in from an earlier attempt that i missed. Thnx for your help. I feel stupid asking this question - El Forum - 08-30-2009 [eluser]kulldox[/eluser] If I understand correctly you have an array: Code: $r['0']['object_id']='Frank'; and you want to convert it to something like this: Code: $v = array(‘Frank’, ‘Todd’, ‘James’); To do that you only have to do the following: Code: foreach ($r as $val){ Code: array(3) { Is it the one you want? I feel stupid asking this question - El Forum - 08-30-2009 [eluser]kgill[/eluser] Just as a follow up, read up on subqueries, unless there's something I'm missing here - there's no reason you had to do this in two different queries. Code: select * from table1 |