简体   繁体   English

如何在PHP中将表格行数据从一页传递到另一页

[英]how to pass table row data from one page to another in php

i am getting a json data and convert into array and echo inside the table. 我正在获取json数据并转换为数组并在表内回显。 I am use session and echo. 我正在使用会话和回声。 now iwant to pass the row data to another page when i try it is getting the last row data when I click. 现在,当我尝试单击时将行数据传递到另一页时,它将获取最后一行数据。 i have a submit buttonin every row when i click on that button it want to pass the row values 我在每行上都有一个提交按钮,当我单击该按钮时,它想传递行值

my output/echo 我的输出/回声

在此处输入图片说明

<?php
    session_start(); ?>
<html>
<head>

        <?php

$baseurl = 'http://202.124.173.189/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 );
        /* Convert json data to array */

        $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 ) 
//$a=$key['DocName'];
 {

        $_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'] ;



    //echo"<td>" .$_SESSION ['ID']=$key['DocName'] ."</td>";*/
?> <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 ><a href='sessiondetails.php?><font face='sans-serif' size=2 color='black'>More>></a></td>
    </tr>
 <?php 
// echo '<pre>';echo print_r ($arr); echo '</pre>';
 }


 }  


 }}
?> 

    </table>
    </form>

    </head>

It passes only the last because you have the same name in all the fields. 它仅通过最后一个,因为您在所有字段中都具有相同的名称。 You could use an array: 您可以使用数组:

<td><input type="text" readonly="" name ="DoctorNo[]" value="<?php echo $key['DocName']?>"  /></td>

So in the next page you will get all names in the $_POST['DoctorNo'] array. 因此,在下一页中,您将获得$_POST['DoctorNo']数组中的所有名称。 The same goes for all your inputs. 所有输入都一样。

Since all the rows of inputs are in the same form, all values are posted when you click submit. 由于输入的所有行都采用相同的形式,因此单击“提交”时,所有值都将发布。

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

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