Get the generated value of a loop - 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: Get the generated value of a loop (/showthread.php?tid=55829) |
Get the generated value of a loop - El Forum - 11-11-2012 [eluser]masentinel900[/eluser] I'm selecting some values from a DB for put them in a dynamic table. Next of generate the table with four(4) rows get from the db, I need get the value generate of each one row for may to do the appropiate download.. This is the controller. Code: foreach($query->result() as $row) This is the side of my controller where I'm add the variables with the DB rows, I need get the variable of hidden input which content the route of the file for be downloaded. The second <th> have a link wich call the download controller and there I get the value of the route trought the userdata parameters.. If I have 20 files diferents and I try to download any always goes download me the last because is getting the route but outside of the foreach. The question is : How I do for may get the dynamic variable inside of the loop? I'm developing a space for downloads. Any suggestion or Idea please let me know.. Get the generated value of a loop - El Forum - 11-11-2012 [eluser]solid9[/eluser] First thing first. Your controller broke the MVC rule. Unless you do $query for testing purpose only. To get the dynamic variable from the loop is you store it into an array. Get the generated value of a loop - El Forum - 11-12-2012 [eluser]masentinel900[/eluser] Ok.. Many thanks by your response. How I do for get the variable trough of the array, If do you can give me a example will be very good.. Get the generated value of a loop - El Forum - 11-12-2012 [eluser]jprateragg[/eluser] I think your problem is here: Code: for($i>1; $i<=$datos['idacta']; $i++) You're essentially saying: For i greater than 1, and i less than or equal to the value in datos['idacta'], and increment by adding i+1. To use the for() function, you need to know the count() of array items in $datos. But as solid9 said, you're violating the MVC framework. For example, in your query, there's no need to store the result as an object then restore it as an array. $query->result_array() will already do this. I think you need to read the user guide sections focusing on views and getting data from a database query. Get the generated value of a loop - El Forum - 11-15-2012 [eluser]masentinel900[/eluser] Hello, Many thanks by your responses. Yes exactly were a problem but just of redound. But only that. But still I have this problem. I don't know how to get each one link of download for may to do the downloads in the link that appropiate. I don't know if maybe not understands what is the problem. I need link the name of each one with the route and that when I see the list for example 20 names, When I click on the name automatically pass their route to the controller download. Already I have all right, But always pass the same route variable, generally is the last. My DB have id, name, description, route, and data. I show all less the route variable that I use it for may to do the download. |