1,105,625 Community Members

How to pass an assosiative array

Member Avatar
amit.mondal.31
Newbie Poster
2 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

**how can i pass an associative array and fetch that same array in submitted page with key=>value format.
**

<?php
//I SUBMIT a.phhp PAGE IN THIS PAGE//
 $f=$_REQUEST['1'];//1st input field value of a.php page
 $s=$_REQUEST['2'];//1st input field value of a.php page
 $t=$_REQUEST['3'];//1st input field value of a.php page
 $sub=$_REQUEST['s'];
 $arr=array($f,$s,$t);

//$arr=array('a'=>"$f","b"=>"$s","c"=>"$t");//i want to send like this as an associative array

 $str=implode(',',$arr);

switch($sub)
{
case 's1':
echo "<script>window.location.href='j2.php?val=$str'</script>";
break;

case 's2':
echo "<script>window.location.href='j3.php?val=$str'</script>";
break;

case 's3':
echo "<script>window.location.href='j4.php?val=$str'</script>";
break;
}
?>

WHAT WILL BE CODE IN PAGE j2.php/j3.php/j4.php TO FETCH $f,$s,$t value with key=>value format(a=>$f,b=>$s,c=>$t)

Member Avatar
diafol
Where are my eyes?
12,986 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,849 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

Instead of passing them, why not include them?

switch($sub)
{
case 's1':
    include "j2.php";
    break;
case 's2':
    include "j3.php";
    break;
case 's3':
    include "j4.php";
    break;
}

Unless you have to go physically to those pages. In which case, save to session variable:

<?php
session_start();
//I SUBMIT a.phhp PAGE IN THIS PAGE//
 $f=$_REQUEST['1'];//1st input field value of a.php page
 $s=$_REQUEST['2'];//1st input field value of a.php page
 $t=$_REQUEST['3'];//1st input field value of a.php page
 $sub=$_REQUEST['s'];

$arr=array('a'=>$f,"b"=>$s,"c"=>$t);

$_SESSION['store'] = $arr;

switch($sub)
{
case 's1':
    header("Locatiob: j2.php");
    exit;
    break;
case 's2':
    header("Locatiob: j3.php");
    exit;
    break;
case 's3':
    header("Locatiob: j4.php");
    exit;
    break;
}
?>

You then pick up the session var in those pages. Also don't use $_REQUEST, use either $_POST or $_GET.

//edit
you don't need the breaks in the switch.

Member Avatar
amit.mondal.31
Newbie Poster
2 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

great .....thnk a ton...actually it was a question ask by interviewer.the quistion was.HOW DO TOU SUBMIT A FORM WITH FORM DATA TO 3 DIFFERENT PAGE USING 3 DIFFERENT SUBMIT BUTTON?so at that instance i got this solution..DO YOU HV ANY OTHER SOLUATION?I know u obiously hv a no of solution.pls share some

Member Avatar
diafol
Where are my eyes?
12,986 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,849 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

Google it?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: