1

我有一个表格,其中包含一个表格,其中包含四个用于比较的数据单元格,并且每列都有一个复选框。当我单击复选框并提交表单时,我只想在新页面中显示选中的表格。我怎样才能做到这一点?任何人都可以帮我举个例子吗?

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comparision of Printers</title>

</head>
<body>

<form action="newpage.php" method="get">
<table width="1023" border="1">
  <tr>
    <td width="193"></td>
    <td class="p1" width="113"><img src="images/upmini.png"/>
      <label>
      <input type="checkbox" name="p[]" value="Printer1" id="CheckboxGroup1_0" />
      Printer1</label>
</td>
    <td class="p2" width="67"><img  src="images/upmini.png"/>
      <label>
      <input type="checkbox" name="p[]" value="Printer2" id="CheckboxGroup1_1" />
      Printer2</label></td>
    <td class="p3" width="67"><img  src="images/upmini.png"/><label>
      <input type="checkbox" name="p[]" value="Printer3" id="CheckboxGroup1_2" />
      Printer3</label></td>
    <td class="p4" width="67"><img  src="images/upmini.png"/><label>
      <input type="checkbox" name="p[]" value="Pritner4" id="CheckboxGroup1_3" />
      Printer4</label></td>
</tr>
<tr>
  <td>Title</td>
    <td class="p1" >Printer1</td>
    <td class="p2" >Printer2</td>
    <td class="p3" >Printer3</td>
    <td class="p4" >Printer4</td>
</tr>
<tr>
    <td>Manufacturer</td>
    <td class="p1" >Personal Portable 3DPrinters (PP3DP) founded by Be</td>
    <td class="p2" >Personal Portable 3DPrinters (PP3DP) founded by Be</td>
    <td class="p3" >Personal Portable 3DPrinters (PP3DP) founded by Be</td>
    <td class="p4" >Personal Portable 3DPrinters (PP3DP) founded by Be</td>
</tr>

</table>
<input type="submit" name="compare" value="compare" />
</form>
</body></html>
4

3 回答 3

2

我认为你应该使用POST而不是GET将你的printermanufacturer信息存储在一个数组中。我使用二维数组来存储信息以使其变得容易。并获取key此数组的值,GET REQUEST然后仅打印与键匹配的值。很简单..

这是完整的功能代码(改变了一点)打印机比较

</head>
<body>
// store your infomation in a arrya and use KEY same as in your form checkbox name
<?php 
  $printers = array(
    'printer1' => array(
                    'title' => 'printer1',
                    'manufacturer' => 'Personal Portable 3DPrinters (PP3DP) founded by Be 1'
                  ),
    'printer3' => array(
                    'title' => 'printer2',
                    'manufacturer' => 'Personal Portable 3DPrinters (PP3DP) founded by Be 2'
                  ),
    'printer2' => array(
                    'title' => 'printer3',
                    'manufacturer' => 'Personal Portable 3DPrinters (PP3DP) founded by Be 3'
                  ),
    'printer4' => array(
                    'title' => 'printer4',
                    'manufacturer' => 'Personal Portable 3DPrinters (PP3DP) founded by Be 4'
                  ) 

    )
 ?>

 //if form submited then print the submited index only
<?php if(isset($_GET['p'])):?>
    <?php $printerIndex = $_GET['p'];?> 
    <table width="1023" border="1">
        <td>Title</td>
            <?php foreach($printerIndex as $index): ?>
                <td class = "p1" ><?php echo $printers[$index]['title']; ?></td>
            <?php endforeach; ?>
        </tr>
        <tr>
            <td>Manufacturer</td>
          <?php foreach($printerIndex as $index): ?>
                <td class = "p1" ><?php echo $printers[$index]['manufacturer']; ?></td>
            <?php endforeach; ?>
        </tr>
    </table> 
<?php endif; ?>

//make the table

<?php if(!isset($_GET['p'])): ?>
<form action="" method="get">
<table width="1023" border="1">
    <tr>
        <td width="193"></td>
        <?php foreach($printers as $printer ): ?>
        <td class="p1" width="113"><img src="images/upmini.png"/>
        <label> <?php echo $printer['title']; ?></label>
        <input type="checkbox" name="p[]" value="<?php echo $printer['title']; ?>" id="CheckboxGroup1_0" />
        </td>
        <?php endforeach; ?>
    </tr>
<tr>
<td>Title</td>
    <?php foreach($printers as $printer): ?>
        <td class = "p1" ><?php echo $printer['title']; ?></td>
    <?php endforeach; ?>
</tr>
<tr>
    <td>Manufacturer</td>
   <?php foreach($printers as $printer): ?>
       <td class = "p1" ><?php echo $printer['manufacturer']; ?></td>
   <?php endforeach; ?>
</tr>

</table>
<input type="submit" name="compare" value="compare" />
</form>
<?php endif; ?>
</body></html>
于 2013-03-24T14:16:52.107 回答
0

检查的打印机作为数组存储p$_GET变量中。例如。在您的示例中检查打印机 1 和 3 将显示以下结果:

<?php var_dump($_GET) ?>

array
  'p' => 
    array
      0 => string 'Printer1' (length=8)
      1 => string 'Printer3' (length=8)
  'compare' => string 'compare' (length=7)
于 2013-03-24T13:24:02.890 回答
0

您只有一张带有多个 TD 的表。

因此,在 newpage.php 中,您可以执行以下操作:

if (isset($_GET['P']))
{ 
    $P = $_GET['P'];
    for ($i=0;$i<sizeof($P);$i++)
    {
        // Show what you like, e.g.
        echo "Printer".$P[$i]."<br />";
    }
}

是你的意思吗?

于 2013-03-24T13:30:14.030 回答