Forums

get data from dinamic table

wachusfleish 05 Aug, 2008
Hi, i´m trying to get data from a html dinamic table that it´s created in the form html with this code:
 <style>
@import url(templates/form.css);
</style>

<?
session_start();
$repositorio=$_SESSION["archivo"];
$sec=$_SESSION["sec"];

echo "<table id='tablapaquetes' border = '1'> \n";
echo "<tr>";
echo "<td bgcolor='#FF0000'><strong> </strong></td>";
echo "<td align='center' bgcolor='#FF0000'><strong>Paquete</strong></td>";
echo "<td align='center' bgcolor='#FF0000'><strong>Seccion</strong></td>";
echo "<td align='center' bgcolor='#FF0000'><strong>Descripcion</strong></td>";
echo "<tr>";
$i=0;

$fichero='/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_gutsy_'.$repositorio.'_binary-i386_Packages';
$archivo = fopen ($fichero, "r"); 
 while (!feof ($archivo))
{
 	while($linea = fgets($archivo))
	{
		if (($linea[0] == 'P') && ($linea[1] == 'a')&& ($linea[2] == 'c'))
        	{ 
			$temp=substr ($linea, 9, 40); 
			$pack=trim($temp);			
                }
		if(($linea[0]=='S')&&($linea[1]=='e')&&($linea[2]=='c'))
		{
			if(($repositorio[0]=='m')&&($repositorio[1]=='a'))
                        {
                              $temp=substr ($linea, 9, 40);
			      $seccion=trim($temp);
                        }if(($repositorio[0]=='m')&&($repositorio[1]=='u'))
                        {
                              $temp=substr ($linea, 20, 40);
			      $seccion=trim($temp);
                        }if(($repositorio[0]=='u')&&($repositorio[1]=='n'))
                        {
                              $temp=substr ($linea, 18, 40);
			      $seccion=trim($temp);
                        }if(($repositorio[0]=='r')&&($repositorio[1]=='e'))
                        {
                              $temp=substr ($linea, 20, 40);
			      $seccion=trim($temp);
                        }
		}
                if (($linea[0] == 'D') && ($linea[1] == 'e')&& ($linea[2] == 's'))
        	{ 
			$temp=substr ($linea, 13, 150); 
			$desc=trim($temp);	
		if(($seccion[0]==$sec[0])&&($seccion[1]==$sec[1])&&($seccion[2]==$sec[2])&&($desc[0]!=''))
	         {
			echo "<td><INPUT type='checkbox' name='";
			echo "check'.$i.''></td>";
			echo "<td align='center' bgcolor='#CCCCCC'><strong>$pack</strong></td>";
				echo "<td align='center' bgcolor='#CCCCCC'><strong>$seccion</strong></td>";
echo "<td align='center' bgcolor='#CCCCCC'><strong>$desc</strong></td>";
				echo "</tr>";
				$i++;
			}
                 }
	}
}
echo $i;

echo "</table>";

session_start();
$_SESSION["i"] = $i;
?> 

<p align="center"><INPUT type="submit" name="boton1" value="Añadir a la distribución"></p>


This code just takes information from a txt file and put it into a table with a checkbox at the begining of every line.

I would like to take the information from the second column (named paquete) when submiting and put it into a new txt file.

Could be something like this?

<?php
session_start();
$contador=$_SESSION["i"];
echo $contador;
for($p=0;$p<$contador;$p++)
{
    $check=check.$p;
    if(( $_POST['$check'] == "on" ))
    {   
       echo $p;
    }
}
?>



Thanks a lot.
Max_admin 05 Aug, 2008
Hi, I can't understand where the problem is ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
wachusfleish 06 Aug, 2008
<?php
session_start();
$contador=$_SESSION["i"];
echo $contador;
for($p=0;$p<$contador;$p++)
{
    $check=check.$p;
    if(( $_POST['$check'] == "on" ))
    {   
       echo $p;
    }
}
?>

Here is the problem, This code doesn´t work. I need to take the information(name) from the column next to the checkboxes selected and get it by the php code when submiting. But this code doesn´t even get me the checkboxes selected. How can i get that information?
Thans a lot
Max_admin 06 Aug, 2008
but why do you need sessions, you can know which boxes are checked through the POST array only!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
wachusfleish 06 Aug, 2008
sorry i doon´t know how to do it could you show me?
I use session just to get how many lines does the table have. and to get every checkbox, but that doesn´t work, and don´t know how to do it as you say.
Max_admin 06 Aug, 2008
Ok, for example, give all your checkboxes names starting with "check" and then loop through all posted data with names starting with "check" only, need a foreach loop with key and data and some PHP string function!

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
wachusfleish 06 Aug, 2008
Hi again, I still don find the way, could you have a look at this code and tell me what i doing wrong?
This is how i create the checkboxes in the html table:
echo "<td> <input type='checkbox' name='chk[]' value='$i'></td>";

and this is how i eval them in the php code after submitting:
foreach($_POST['chk'] as $value)
{
if($value=='on')
{
echo "checked";
}
}
GreyHead 06 Aug, 2008
Hi wachusfleish,

The value isn't going to be 'on' it will be '$i' or whatever that evaluates to.

Turn on Debug and see what is really in the $_POST array, that will help you write your PHP.

Bob
wachusfleish 06 Aug, 2008
Thanks a lot greyhead and admin.
Debug helped me a lot. THANK YOU, without your help i would have still been block.
This topic is locked and no more replies can be posted.