![]() |
newbie question: Double Foreach - 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: newbie question: Double Foreach (/showthread.php?tid=33813) |
newbie question: Double Foreach - El Forum - 09-09-2010 [eluser]Razedd[/eluser] Hello I want to get two query's in a two foreach's This is the non CI version and that works but i cant get it in CI. Code: $res=mysql_query("SELECT ResDatum FROM reservering group by ResDatum order by ResDatum ASC") or die(mysql_error()); This is what i have made up until now Code: function reserveer() Can someone explain how to do this or maybe find a complete different way to achieve the same Thank you greetings Razedd newbie question: Double Foreach - El Forum - 09-10-2010 [eluser]Razedd[/eluser] is this impossible? or don't you understand what i want? newbie question: Double Foreach - El Forum - 09-10-2010 [eluser]Met[/eluser] Code: $data['query2']=$this->db->query('SELECT * FROM `reservering` WHERE `ResDatum`='.$query1->result().''); this line is definitely wrong - the WHERE condition is a result set this is untested, but do all the foreaching before you pass the data so, for every result from the first query, you want to do another query using $row['ResDatum'] as a WHERE condition. and store results of THIS query in to an array. then pass that to the view. I see what you're trying to do but I don't think it will ever work that way - there is a huge difference between while() and foreach() in my head its something like Code: $query1=$this->db->query('SELECT Resdatum FROM `reservering` GROUP BY `ResDatum`'); there might be a problems with performance though with this. edit - on a second thought, could you not just use a JOIN? newbie question: Double Foreach - El Forum - 09-10-2010 [eluser]Bart v B[/eluser] The use of GROUP BY is nog possible here as you demonstrate. You only can use GROUP BY with agegrate functions. Like COUNT SUM. Your mysql configuration is not ok. Use strict mode then you see what i mean ![]() Better is to look wih DATE_DIFF() and use an alias. Then you only have one foreach() loop. In short, you can use one query here. I don't have the time now to make an example, but give it a try. newbie question: Double Foreach - El Forum - 09-10-2010 [eluser]Razedd[/eluser] [quote author="Met" date="1284123824"] so, for every result from the first query, you want to do another query using $row['ResDatum'] as a WHERE condition. and store results of THIS query in to an array. then pass that to the view. [/quote] Thanks, that should do the trick i guess, if come this far now Code: $query1[]=$this->db->query('SELECT Resdatum FROM `reservering` GROUP BY `ResDatum`'); I made that now but there is an error Code: Fatal error: Call to a member function result() on a non-object in C:\wamp\www\Code_ignitor\system\application\controllers\restaurant.php on line 21 Thanks for the help allready, it was stupid from me not to think of this Kind regards Razedd newbie question: Double Foreach - El Forum - 09-10-2010 [eluser]Razedd[/eluser] Okhe i fixed it and i figure i should post it.. After a talk with some people i made it like this Code: $data['query']=$this->db->query('SELECT * FROM `reservering` ORDER BY `ResDatum`,`ResTafel`, `ResTijd` ASC'); now it works fine but its probably not optimaly using CI, if you see things that just scream to be improved please say so. Thanks for youre help, Razedd |