简体   繁体   English

如何将php数组数据从一页传递到另一页

[英]how to pass php array data from one page to another

i am getting json data and i convert into php array and echo inside the table now i want to pass the selected row data to another page when i select the row it is not taking that value itis taking the last row data how can i solve it . 我正在获取json数据并将其转换为php数组并在表内回显,现在我想将选择的行数据传递给另一页,当我选择该行时,它没有采用该值,因此我要采用最后一行数据该如何解决。 thanks in advance. 提前致谢。

这是我的第一页

  <?php
 require 'gettoken1.php';  
session_start(); 
?>
<html>
<head>


<?php

if (isset($_POST['submit']))
 {

            {
$baseurl = 'http://host/api/v1/doctorAvailability';    
$rawPOSTdata = array
                (
                    "type" => "private",
                    "hosID" => $_POST['hosMaptxt'],
                    "specID" => $_POST['specialityMaptxt'],
                     "date" => $_POST['date'],
                    "name" => '%'.$_POST['docname'].'%'
                );

$curl = curl_init($baseurl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"Authorization: Bearer $atoken")); 
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($rawPOSTdata));    
$response = curl_exec($curl);
curl_close($curl);

 if( $response )
     {
        if ( isset($result->error) )die( $result->error_message );


        $arr=json_decode( $response, true );

    ?>
<body>
        <form method ="post" action="sessiondetails.php" >

    <h2> Avilable Doctors </h2>             
    <table >
        <tr>
            <th> Doctor</th>
            <th>Specialition</th>
            <th> Hospital </th>
            <th> Town </th>
            <th> Date </th>
            <th> Day </th>
            <th> Booking </th>
        </tr>
<?php
foreach($arr['data']['resultMap'] as $key ) 

 {

        $_SESSION ['HosCode']=$key['HosCode'] ;
        $_SESSION ['SpecializationId']=$key['SpecializationId'] ;
        $_SESSION ['DoctorNo']=$key['DoctorNo'] ;
        $_SESSION ['AppDay']=$key['AppDay'] ;
        $_SESSION ['AppDate']=$key['AppDate'] ;
        $_SESSION ['DocName']=$key['DocName'] ;
        $_SESSION ['SpecName']=$key['SpecName'] ;
        $_SESSION ['HosName']=$key['HosName'] ;


?> 
        <tr>

        <td><input type="text" readonly="" name ="DoctorNo[]" value="<?php echo $key['DocName']?>"  /></td>
        <td><input type="text" readonly="" name ="SpecializationId[]"  value="<?php echo $key['SpecName']?> "/></td>
        <td><input type="text" readonly="" name ="HosCode[]" value="<?php echo $key['HosName']?>" /></td>
        <td><input type="text" readonly="" name ="HosTown[]"  style="width:110px "value="<?php echo $key['HosTown']?>"/></td>
        <td><input type="text"  readonly="" name ="AppDate[]"  style="width:80px "  value="<?php echo $key['AppDate']?>" /></td>
        <td><input type="text"  readonly="" name ="AppDay[]"  style="width:80px " value="<?php echo $key['AppDay']?>" /></td>
         <td ><input type="submit" value="click" name="submit"></td>
        </tr>

 <?php 

 }


 }  


 }}
?> 

    </table>
    </form>
    </head>
    </html>

这是我的第一页2 here is the codding 这是外套

  <html>
<head>

    <link href='style1.css' rel='stylesheet' type='text/css'>
<?php

 session_start();
        $A=$SpecializationId=$_SESSION ['SpecializationId'] ;
        $b=$DoctorNo=   $_SESSION ['DoctorNo'] ;
        $c= $_SESSION ['AppDay'];
        $d= $_SESSION ['AppDate'] ; 
        $e=$_SESSION ['HosCode'];       
        //$hospital=$_SESSION ['HosName'];
        //$specialization=$_SESSION ['SpecName'];
        //$doctor=$_SESSION ['DocName'];
    $baseurl = 'http://host/api/v1/doctorSessions';    
    $rawPOSTdata = array
                (

                    "hosID" =>$e,
                    "specID" => $A,
                    "docNo" =>$b,
                    "day" => $c,
                    "date" =>  $d,  
                );

$curl = curl_init($baseurl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"Authorization: Bearer $atoken")); 
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($rawPOSTdata));    
$response = curl_exec($curl);
curl_close($curl);

 if( $response )
     {
        if ( isset($result->error) )die( $result->error_message );


        $arr=json_decode( $response,true);
        ?>
<body>

    <form method ="post" action =" patientdetails.php"> 
    <h2> Doctor Details </h2>       
    <table>
        <tr>
            <td style="width:10%"><label> Doctor </label>
            </td> <td style="width:75%"> <?php echo  $_SESSION ['DocName']?></td>
        </tr>
        <tr>
            <td><label>Specialition </label> </td>
            <td> <?php echo $_SESSION ['SpecName'];?></td>
        </tr>
        <tr>
            <td><label>Hospital </label></td>
            <td>  <?php echo    $_SESSION ['HosName'];?></td>
        </tr>
    </table>

        <table>
            <tr>
            <th> Day </th>
            <th> Date</th>
            <th>Status</th>
            <th> Time </th>
            <th> Amount </th>
            <th> Click </th>
            </tr>

            <?php
foreach($arr['data']['result'] as $key ) 


    {

        $_SESSION ['Hosid']=$key['Hosid'] ;
        $_SESSION ['Remark']=$key['Remark'] ;
        $_SESSION ['Docno']=$key['Docno'] ;
        $_SESSION ['Sday']=$key['Sday'] ;
        $_SESSION ['ShowDate']=$key['ShowDate'] ;
        $_SESSION ['Ttime']=$key['Ttime'] ;
        $_SESSION ['amount']=$key['amount'] ;

?>


    <tr>
    <td><input type="text" readonly="" name ="DoctorNo"value="<?php echo $key['Sday'] ?>" /></td>
    <td><input type="text" readonly="" name ="HosCode" value="<?php echo $key['ShowDate']?>" /></td>
    <td><input type="text" readonly="" name ="HosCode" value="<?php echo $key['Remark']?>" /></td>
    <td><input type="text" readonly="" name ="HosTown"  style="width:110px "value="<?php echo $key['Ttime'] ;?>"/></td>  
    <td><input type="text" readonly="" name ="HosTown"  style="width:110px "value="<?php echo" RS.". $key['amount'];?>"/></td>  
    <td>  <input type="submit" value="Confirm" name ="confirm"></td>
    </tr>

 <?php

 } 

    } 

?> 

</table>
</form>
    </head>

</html>

The Usage of session_start(); session_start();的用法session_start(); in both Scripts seem a little out of Place. 在两个脚本中似乎都不合时宜。 REASON: When you want to use Sessions in your Code, you have to make sure that no White-Space or any other Characters are OUTPUT before starting the SESSION. 原因:当您想在代码中使用会话时,必须确保在开始SESSION之前没有空白或其他任何字符输出。 In other words, Starting the Session should be the 1st Line of Code in your Script. 换句话说, 启动会话应该是脚本中的第一行代码。 Here's how: 这是如何做:

YOUR 1 ST SCRIPT COULD HAVE STARTED OUT BETTER LIKE SO: 您的1 ST脚本可以有这么开始了更好的,如:

<?php    // NOTICE THAT THERE IS NO SPACE OR CHARACTER BEFORE <?php
         // NOTICE ALSO THAT STARTING THE SESSION IS THE FIRST LINE AFTER <?php 
    session_start();              // <= STEP 1: START SESSION
    require 'gettoken1.php';      // <= STEP 2: IMPORT DEPENDENCIES
?>

    <html>  <!-- STEP 3: YOU MAY NOW SEND DATA TO THE OUTPUT STREAM -->
        <head>
           <!-- REST OF THE MARK-UP -->

YOUR 2 ND SCRIPT COULD HAVE BEEN BETTER LIKE SO: 您2 ND SCRIPT本来像这样更好:

<?php   // NOTICE THAT THERE IS NO SPACE OR CHARACTER BEFORE <?php
        // NOTICE ALSO THAT STARTING THE SESSION IS THE FIRST LINE AFTER <?php 
        session_start();    // <= STEP 1: START SESSION
                            // <= STEP 2: CONTINUE WITH THE REST OF THE CODE
        $A       =  $SpecializationId   =   $_SESSION ['SpecializationId'] ;
        $b       =  $DoctorNo           =   $_SESSION ['DoctorNo'] ;
        $c       =  $_SESSION ['AppDay'];
        $d       =  $_SESSION ['AppDate'] ;
        $e       =  $_SESSION ['HosCode'];
        $baseurl = 'http://host/api/v1/doctorSessions';

        //$hospital=$_SESSION ['HosName'];
        //$specialization=$_SESSION ['SpecName'];
        //$doctor=$_SESSION ['DocName'];

        $rawPOSTdata = array(               
            "hosID"    => $e,
            "specID"   => $A,
            "docNo"    => $b,
            "day"      => $c,
            "date"     => $d,
        );

        $curl       = curl_init($baseurl);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"Authorization: Bearer $atoken"));
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($rawPOSTdata));
        $response = curl_exec($curl);
        curl_close($curl);

        if($response){
            if ( isset($result->error) ){die($result->error_message);}                  
            $arr  =  json_decode( $response,true);

    ?>
<html>
<head>      
    <link href='style1.css' rel='stylesheet' type='text/css'>
</head>
<body>  
    <form method ="post" action =" patientdetails.php">
        <h2> Doctor Details </h2>
        <table>
            <tr>
                <td style="width:10%"><label> Doctor </label>
                </td> <td style="width:75%"> <?php echo  $_SESSION ['DocName']?></td>
            </tr>
            <tr>
                <td><label>Specialition </label> </td>
                <td> <?php echo $_SESSION ['SpecName'];?></td>
            </tr>
            <tr>
                <td><label>Hospital </label></td>
                <td>  <?php echo    $_SESSION ['HosName'];?></td>
            </tr>
        </table>

        <table>
            <tr>
                <th> Day </th>
                <th> Date</th>
                <th>Status</th>
                <th> Time </th>
                <th> Amount </th>
                <th> Click </th>
            </tr>

            <?php
                foreach($arr['data']['result'] as $key){                        
                    $_SESSION ['Hosid']    = $key['Hosid'] ;
                    $_SESSION ['Remark']   = $key['Remark'] ;
                    $_SESSION ['Docno']    = $key['Docno'] ;
                    $_SESSION ['Sday']     = $key['Sday'] ;
                    $_SESSION ['ShowDate'] = $key['ShowDate'] ;
                    $_SESSION ['Ttime']    = $key['Ttime'] ;
                    $_SESSION ['amount']   = $key['amount'] ;

            ?>                      

            <tr>
                <td><input type="text" readonly="" name ="DoctorNo"value="<?php echo $key['Sday'] ?>" /></td>
                <td><input type="text" readonly="" name ="HosCode" value="<?php echo $key['ShowDate']?>" /></td>
                <td><input type="text" readonly="" name ="HosCode" value="<?php echo $key['Remark']?>" /></td>
                <td><input type="text" readonly="" name ="HosTown"  style="width:110px "value="<?php echo $key['Ttime'] ;?>"/></td>
                <td><input type="text" readonly="" name ="HosTown"  style="width:110px "value="<?php echo" RS.". $key['amount'];?>"/></td>
                <td>  <input type="submit" value="Confirm" name ="confirm"></td>
            </tr>

               <?php    
            }       
        }

            ?>

        </table>
    </form>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM