foreach instead of while in querys - 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: foreach instead of while in querys (/showthread.php?tid=54158) |
foreach instead of while in querys - El Forum - 08-25-2012 [eluser]Steeep[/eluser] Well for starters, excuse my bad English, not my native language. I have the following code, but I get problems when displaying results database & save them to a file. Code: $mode = !file_exists(APPPATH . 'config/forum.php') ? 'x' : 'w'; It should show the results as follows: Code: $config['forum']['closed'] = "1"; Pero solo me muestra & guarda solo el último resultado, así: Code: $config['forum']['friendly_urls'] = "0"; And if I change the foreach for while, I get errors & saves me the results correctly. The code is this: Code: if(!file_exists("config/forum.php")) I can do? foreach instead of while in querys - El Forum - 08-25-2012 [eluser]NeoArc[/eluser] The problem is here, you are overwritting $settings every time the loop runs: Code: $settings = "\$config['forum']['{$setting['title']}'] = \"{$setting['value']}\";\n"; Just change it to the correct string operator, (and declare $settings before the foreach block) Code: $settings .= "\$config['forum']['{$setting['title']}'] = \"{$setting['value']}\";\n"; foreach instead of while in querys - El Forum - 08-25-2012 [eluser]Steeep[/eluser] Creo que no hay problema en que lo diga en español.. Solo era eso, & crei que borrando el punto sería mejor, pero ya veo que no, gracias |