![]() |
loop problem - 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: loop problem (/showthread.php?tid=42737) |
loop problem - El Forum - 06-17-2011 [eluser]Bigil Michael[/eluser] i want to execute multiple while loop like this Code: <?php $selected_ member = "select id,name from members" my table contains 5 entries so it must print 25 rows it prints 5 rows only once that means the loop execute only once. i dont know what is the problem here ?????? can anyone help me???? loop problem - El Forum - 06-17-2011 [eluser]Seb[/eluser] I think you should store the resulting arrays into variables, and then loop over those variables instead of looping directly on the queries. loop problem - El Forum - 06-17-2011 [eluser]vitoco[/eluser] This may work Code: <? loop problem - El Forum - 06-17-2011 [eluser]CroNiX[/eluser] because both of your loops use $id, $name, so the inner loop is overwriting the outer loops variables. Just rename the inner loop variables to something else. loop problem - El Forum - 06-17-2011 [eluser]vitoco[/eluser] @CroNiX it's right , that's because i prefer foreach to while. loop problem - El Forum - 06-17-2011 [eluser]CroNiX[/eluser] I was referring to the original post. in both loops he is doing list($id, $name). 2nd loop's $id, $name overwrites first loops $id, $name. 2nd loop should be $id2, $name2 or something different, although I don't see the logic in what he is doing in the first place. He is retrieving the same results over and over because there is no where statement. loop problem - El Forum - 06-17-2011 [eluser]vitoco[/eluser] i know yo do... loop problem - El Forum - 06-17-2011 [eluser]jmadsen[/eluser] @Bigil MM - can you explain what you are doing this for? your code looks very strange to me, unless you are trying to create a grid where every value matches up against every other value? If that's the case, there is a trick to create a Cartesian Product that will be much simpler and efficient. If it's not, you may be doing something incorrectly |