我得到一个json数据并转换成数组并在表内回显。 我使用session和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>
答案 0 :(得分:0)
它仅传递最后一个,因为您在所有字段中具有相同的名称。你可以使用一个数组:
<td><input type="text" readonly="" name ="DoctorNo[]" value="<?php echo $key['DocName']?>" /></td>
因此,在下一页中,您将获得$_POST['DoctorNo']
数组中的所有名称。
所有输入都是如此。
由于所有输入行都采用相同的形式,因此当您单击“提交”时,将发布所有值。