0

hi there..

well lets say I do have a multidimensional array of the sort shown below..
Now I do need to pass on the arrays using checkboxes..!! how do I assign single row to each checkbox so that when I onclick it posts the value to the function on the top...

<?php
session_start();


$arraylen=4; // zero based 
  $i=0; 
  $allValuesPresent=1; 
            
    
                    
        if (isset($_POST['table'])) { 
               foreach ($_POST['table'] as $arr) { 
                    if (! isset($arr[$i])) { 
                         $allValuesPresent = 0; 
                            break; 
                        } 
 // Will get overwritten by query if any are missing 
 
 $qresult[$i]=$arr; 
 $i++; 
} 

    // return array of results

// do your query 

echo $qresult[0][1];


}


?>

<html>
<form method="POST" name="myform2" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php    $table = array(
                        //  array('id','state','lat_hi','long_hi','lat_low','long_low'),  //field names
                            array(1,'andaman',13.59,94,06.73,92.53),
                            array(2,'AP',     19.87,84.78,12.59,76.45),
                            array(3,'Gujarat',24.72,74.55,20.15,68.35),
                            array(4,'kerala' ,12.75,77.37,08.18,74.86),
                            array(5,'punjab' ,32.46,76.93,29.53,73.87),
                
            );
                        
$_POST['table']= $table;    ?>



</form>                    
</html>

Edited by mani2604: n/a

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by mani2604
0

"when I onclick it posts the value to the function on the top..."
what does it exactly means?

You want to use $table array right?
Post your exact html output requirement.

0

well I do have a multidimensional array and now i do want to assign a single row to a single checkbox && when the checkbox is on I want to post the values to the below function..

Sory if I am not clear enough again.....

function GetStoreTable() {

$arraylen=4; // zero based 
  $i=0; 
  $allValuesPresent=1; 

     if (isset($_POST['table'])) { 
               foreach ($_POST['table'] as $arr) { 
                    if (! isset($arr[$i])) { 
                         $allValuesPresent = 0; 
							break; 
						} 

 
 $qresult[$i]=$arr; 
 $i++; 
} 



   return $qresult;

}

}

Edited by mani2604: n/a

0
<?php
session_start();

if(isset($_REQUEST['submit']))//---- form is submitted -----
{
	$tab = $_REQUEST['tab'];
	for($i=0;$i<count($tab);$i++)
	{
		//--- here you are having all values checked by user. you can explode it by :: for further use. you can call your required function here.
		echo '<br>'.$tab[$i]." is checked.";
	}
}
?>

<html>
<form method="POST" name="myform2" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php    $table = array(
                        //  array('id','state','lat_hi','long_hi','lat_low','long_low'),  //field names
                            array(1,'andaman',13.59,94,06.73,92.53),
                            array(2,'AP',     19.87,84.78,12.59,76.45),
                            array(3,'Gujarat',24.72,74.55,20.15,68.35),
                            array(4,'kerala' ,12.75,77.37,08.18,74.86),
                            array(5,'punjab' ,32.46,76.93,29.53,73.87),                
            );                        
?>

<? for($i=0;$i<count($table);$i++){?>
<br><input name="tab[]" type="checkbox" value="<?=$table[$i][0]?>::<?=$table[$i][1]?>::<?=$table[$i][2]?>::<?=$table[$i][3]?>::<?=$table[$i][4]?>::<?=$table[$i][5]?>">
Id : <?=$table[$i][0]?>, Name : <?=$table[$i][1]?>
<? } ?>
<br><br><input name="submit" value="submit" type="submit">
</form>                    
</html>

This is just demo kinda thing.
you should not use function in this manner, where you want to use directly post values in function.
also not sure this is wat u want.

0

Hey thanks a lot... that was helpful... I will try adding the function and checkout how this thing works out:-)

Edited by mani2604: n/a

0

Hi now I do get this error when i try to use 'explode' -->

if(isset($_REQUEST['submit']))//---- form is submitted -----
      {

      $tab = $_REQUEST['tab'];
      var_dump($tab);

      for($i=0;$i<count($tab);$i++)
 
      {

      //--- here you are having all values checked by user. you can explode it by :: for further use. you can call your required function here.
      $extent = explode("::",$tab);
      var_dump($extent);
      echo '<br>'.$tab[$i]." is checked.";

      }

      }

Error:- array(1) { [0]=> string(37) "5::punjab::32.46::76.93::29.53::73.87" } Warning: explode() expects parameter 2 to be string, array given in C:\ms4w\Apache\htdocs\test24.php on line 16 NULL

Edited by mani2604: n/a

0

actually I aint getting any error If i use [TEX]$extent = explode("::",$tab[$i]);[/TEX] but I miss the multidimensional array format now; as single rows surfaced up....

Edited by mani2604: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.