Welcome Guest, Not a member yet? Register   Sign In
Get the generated value of a loop
#1

[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)
  {  
   $datos = array(
   'idacta' => $row->idacta,
   'rutaarchivo' => $row->rutaarchivo,
   'descripcion' => $row->descripcion,
   'fechademodificacion' => $row->fechademodificacion,
   );
   for($i>1; $i<=$datos['idacta']; $i++)
   {  
   $content .= "  
   <tr>
    <td id='$i'>&lt;input name='opcion-res' type='radio' align='center'/&gt;&lt;/td>
    <td id='$i'><a href='download'>$datos[rutaarchivo]</a></td>
    <td id='$i'>$datos[descripcion]</td>
    <td id='$i'>$datos[fechademodificacion]</td>
    &lt;input id='$i' type='hidden' name='hola' value='$datos[rutaarchivo]'/&gt;
   </tr>
   ";
   }  
   $this->session->set_userdata('logged_content', $datos);
   $this->output->set_output($content);
  }

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..
#2

[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.
#3

[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..
#4

[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.
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB