嘿我目前遇到的问题是尝试使我的输入按钮具有我需要的id /服务器的值,它显示不同的值这是我的代码当前的样子我知道HTML和表单无效我将重构它,但是我正在尝试获取服务器标识符和id标识符以交叉到另一个页面
<?php
$propertyType = $xmlDom1->getElementsByTagName('PropertyType');
$rent = $xmlDom1->getElementsByTagName('rates');
$rooms = $xmlDom1->getElementsByTagName('rooms');
//$server = $xmlDom1->getElementsByTagName('server');
$propertyServer = $xmlDom1->getElementsByTagName('Property');
$propertyID = $xmlDom1->getElementsByTagName('Property');
$imageURL = $xmlDom1->getElementsByTagName('url');
$imageAlt = $xmlDom1->getElementsByTagName('altText');
$server = $propertyID->item($i)->getAttribute('server');
echo '<form action="level5Details.php" method="get" enctype="application/x-www-form-urlencoded">';
echo '<table><th>Type:</th><th>Rent:</th><th>Rooms:</th><th>Server</th>';
$records = $xmlDom1->documentElement->childNodes;
for ($i = 0; $i < $records->length; $i++) {
echo "<tr><td>".$propertyType->item($i)->nodeValue."</td>";
echo "<td>".$rent->item($i)->nodeValue."</td>";
echo "<td>".$rooms->item($i)->nodeValue."</td>";
echo "<td>".$propertyServer->item($i)->getAttribute('Server')."</td>";
echo '<td><img src="data:image/jpeg;base64,'.$imageURL->item($i)->nodeValue.'" alt="'.$imageAlt->item($i)->nodeValue.'"></img></td>';
?>
<td>
<button class="submit" type="submit" value="<?php echo $propertyID->item($i)->getAttribute('pid'); ?>" name="submit22">something </button>
</td>
</tr>
<?php
}
?>
</form>
答案 0 :(得分:0)
如果您尝试使用一个按钮生成大量表单,那么您需要将表单放在像这样的表格单元格中
将要传递的数据项放在隐藏字段中而不是尝试将2个数据项放在按钮值中可能也很有用
<?php
$propertyType = $xmlDom1->getElementsByTagName('PropertyType');
$rent = $xmlDom1->getElementsByTagName('rates');
$rooms = $xmlDom1->getElementsByTagName('rooms');
//$server = $xmlDom1->getElementsByTagName('server');
$propertyServer = $xmlDom1->getElementsByTagName('Property');
$propertyID = $xmlDom1->getElementsByTagName('Property');
$imageURL = $xmlDom1->getElementsByTagName('url');
$imageAlt = $xmlDom1->getElementsByTagName('altText');
$server = $propertyID->item($i)->getAttribute('server');
echo '<table><th>Type:</th><th>Rent:</th><th>Rooms:</th><th>Server</th>';
$records = $xmlDom1->documentElement->childNodes;
for ($i = 0; $i < $records->length; $i++) {
echo "<tr><td>".$propertyType->item($i)->nodeValue."</td>";
echo "<td>".$rent->item($i)->nodeValue."</td>";
echo "<td>".$rooms->item($i)->nodeValue."</td>";
echo "<td>".$propertyServer->item($i)->getAttribute('Server')."</td>";
echo '<td><img src="data:image/jpeg;base64,'.$imageURL->item($i)->nodeValue.'" alt="'.$imageAlt->item($i)->nodeValue.'"></img></td>';
$pid = $propertyID->item($i)->getAttribute('pid');
?>
<td>
<form action="level5Details.php" method="get" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="pid" value="<?php echo $pid;?>">
<input type="hidden" name="server" value="<?php echo $server;?>">
<button class="submit" type="submit" value="submit" name="submit22">something</button>
</form>
</td>
</tr>
<?php
}
?>
如果您只是希望按钮携带所有数据并且只有一个表单,则必须将2个数据项打包成一个字符串并将其作为按钮的值发送
<?php
$propertyType = $xmlDom1->getElementsByTagName('PropertyType');
$rent = $xmlDom1->getElementsByTagName('rates');
$rooms = $xmlDom1->getElementsByTagName('rooms');
//$server = $xmlDom1->getElementsByTagName('server');
$propertyServer = $xmlDom1->getElementsByTagName('Property');
$propertyID = $xmlDom1->getElementsByTagName('Property');
$imageURL = $xmlDom1->getElementsByTagName('url');
$imageAlt = $xmlDom1->getElementsByTagName('altText');
$server = $propertyID->item($i)->getAttribute('server');
echo '<form action="level5Details.php" method="get" enctype="application/x-www-form-urlencoded">';
echo '<table><th>Type:</th><th>Rent:</th><th>Rooms:</th><th>Server</th>';
$records = $xmlDom1->documentElement->childNodes;
for ($i = 0; $i < $records->length; $i++) {
echo "<tr><td>".$propertyType->item($i)->nodeValue."</td>";
echo "<td>".$rent->item($i)->nodeValue."</td>";
echo "<td>".$rooms->item($i)->nodeValue."</td>";
echo "<td>".$propertyServer->item($i)->getAttribute('Server')."</td>";
echo '<td><img src="data:image/jpeg;base64,'.$imageURL->item($i)->nodeValue.'" alt="'.$imageAlt->item($i)->nodeValue.'"></img></td>';
$dataPackage = $propertyID->item($i)->getAttribute('pid') . ':' . $server;
?>
<td>
<button class="submit" type="submit" value="<?php echo $dataPackage;?>" name="submit22">something</button>
</td>
</tr>
<?php
}
</table>
</form>
?>
现在在接收表单中解压缩数据以供使用
<?php
// usual checks for things existing
list($pid, $server) = explode(':', $_GET['submit22'];