duanliangman5398 2013-11-01 17:09
浏览 51
已采纳

如何选择表的两列或多列并通过GET / POST发送?

I have a simple HTML table generated using Mysql and PHP.

I would like to choose one row of my table, and send two or more contents through GET or POST to another page, using the easy way as possible.

Today, I can send only one parameter using "radio" button like this:

<form method="GET" action="table.php">
<table>
<?php
$query="SELECT * from prices ORDER BY region limit 10";
$result=mysql_query($query,$connection);
while ($linha = mysql_fetch_array($result)) {
?>
<tbody>
    <tr>
     <td><input type="radio" name="region"  value="<?php echo $linha['region'] ?>" /></td>
     <td><?php echo $row['type']; ?></td>
     <td><?php echo $row['region']; ?></td>
     <td><?php echo $row['platform']; ?></td>  
     <td><?php echo $row['price']; ?></td>                                      
    </tr>
</tbody>

<?php
}
?>

</table>
<input type="submit" value="Submit"/>       
</form>

So, if I click in "Submit" button I got:

table.php?region=ap-northeast-1

How can I get, for example:

tabela.php?region=ap-northeast-1&type=c1.medium

=== Edit:

That's how my table looks like:

type    region  platform    price $/h
m3.xlarge   ap-northeast-1  windows 0.980
hs1.8xlarge ap-northeast-1  rhel    5.810
hi1.4xlarge ap-northeast-1  rhel    3.960
m1.medium   ap-northeast-1  windows 0.230
cg1.4xlarge ap-northeast-1  rhel    4.450
cc2.8xlarge ap-northeast-1  rhel    3.100
c1.xlarge   ap-northeast-1  rhel    0.855
c1.medium   ap-northeast-1  rhel    0.254
m2.4xlarge  ap-northeast-1  rhel    2.135
m2.2xlarge  ap-northeast-1  rhel    1.079

And I would like to be able to sent the values "type" AND "platform" to another page :)

  • 写回答

3条回答 默认 最新

  • douji6199 2013-11-02 03:14
    关注

    I have three ideas:

    You could use jQuery (javascript) for this

    <form method="get" action="table.php">
    <input type="hidden" name="platform" id="platform" />
    <table>
    <tr>
        <td>type</td>
        <td>region</td>
        <td>platform</td>
        <td>price</td>
        <td>$/h</td>
    </tr>
    <tr>
        <td><input type="radio" class="regionSelectRadio" name="region"  value="m3.xlarge" /></td>
        <td>m3.xlarge</td>
        <td>ap-northeast-1</td>
        <td>windows</td>
        <td>0.980</td>
    </tr>
    </table>
    <input type="submit" value="Submit"/> 
    </form>
    
    <script>
        jQuery(document).ready(function(){
            jQuery('.regionSelectRadio').click(function(){
                jQuery('#platform').attr('value', jQuery(this).parent().children().eq(3).html() );
            });
        });
    </script>
    

    You could use a separate form for every record:

    <form method="get" action="table.php">
    
    <table>
    <tr>
        <td>type</td>
        <td>region</td>
        <td>platform</td>
        <td>price</td>
        <td>$/h</td>
    </tr>
    <tr>
        <td><input type="submit" value="Select"/> <input type="hidden" name="region"  value="m3.xlarge" />
        <input type="hidden" name="platform" value="windows" />
        </td>
        <td>m3.xlarge</td>
        <td>ap-northeast-1</td>
        <td>windows</td>
        <td>0.980</td>
    </tr>
    </table>
    </form>
    
    <form method="get" action="table.php">
    
    <table>
    <tr>
        <td>type</td>
        <td>region</td>
        <td>platform</td>
        <td>price</td>
        <td>$/h</td>
    </tr>
    <tr>
        <td><input type="submit" value="Select"/> <input type="hidden" name="region"  value="m3.xlarge" />
        <input type="hidden" name="platform" value="windows" />
        </td>
        <td>m3.small</td>
        <td>ap-southeast-1</td>
        <td>unix</td>
        <td>0.980</td>
    </tr>
    </table>
    </form>
    

    You can also put the two values in the same option input and then split in php:

    <form method="get" action="table.php">
    
    <table>
    <tr>
        <td>type</td>
        <td>region</td>
        <td>platform</td>
        <td>price</td>
        <td>$/h</td>
    </tr>
    <tr>
        <td><input type="radio" class="regionSelectRadio" name="region"  value="m3.xlarge;windows" />
        </td>
        <td>m3.xlarge</td>
        <td>ap-northeast-1</td>
        <td>windows</td>
        <td>0.980</td>
    </tr>
    <tr>
        <td>type</td>
        <td>region</td>
        <td>platform</td>
        <td>price</td>
        <td>$/h</td>
    </tr>
    <tr>
        <td><input type="radio" class="regionSelectRadio" name="region"  value="m3.small;unix" />
        </td>
        <td>m3.small</td>
        <td>ap-southeast-1</td>
        <td>unix</td>
        <td>0.980</td>
    </tr>
    </table>
    </form>
    
    <?php
    $values = explode(';',$_REQUEST['region'])
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题