如何选择表的两列或多列并通过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 :)
我有一个使用Mysql和PHP生成的简单HTML表。 p>
I 我想选择我的表格的一行,并通过GET或POST将两个或多个 strong>内容发送到另一个页面,尽可能使用简单方法。 p>
今天 ,我只能使用“radio”按钮发送一个 strong>参数,如下所示: p>
因此,如果我点击“提交”按钮,我得到: p>
我如何获得,例如: p>
===编辑: p>
这就是我的表格的样子: p>
我希望能够将值“type” AND strong>“platform”发送到另一页:) p>
div>
&lt; form method =“GET”action =“table.php “&gt;
&lt; table&gt;
&lt;?php
$ query =”SELECT * from price ORDER BY region limit 10“;
$ result = mysql_query($ query,$ connection);
while($ linha = mysql_fetch_array($ result)){
?&gt;
&lt; tbody&gt;
&lt; tr&gt;
&lt; td&gt;&lt; input type =“radio”name =“region”value =“&lt;?php echo $ linha ['region']?&gt;“ /&gt;&lt; / td&gt;
&lt; td&gt;&lt;?php echo $ row ['type']; ?&gt;&lt; / td&gt;
&lt; td&gt;&lt;?php echo $ row ['region']; ?&gt;&lt; / td&gt;
&lt; td&gt;&lt;?php echo $ row ['platform']; ?&GT;&LT; / TD&GT;
&lt; td&gt;&lt;?php echo $ row ['price']; ?&GT;&LT; / TD&GT;
&lt; / tr&gt;
&lt; / tbody&gt;
&lt;?php
}
?&gt;
&lt; / table&gt;
&lt; input type =“submit”value =“提交” /&GT;
&lt; / form&gt;
code> pre>
table.php?region = ap-northeast-1
code> pre>
tabela.php?region = ap-northeast-1&amp; type = c1.medium
code> pre>
类型区域平台价格$ / 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
code> pre>
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'])
?>
you can use hidden field for type
<input type="hidden" name="type" value="<?php echo $row['type']; ?>" />
You can use input type hidden
to do this:
<td><input type="hidden" name="type" value="<?php echo $row['type']; ?>"><?php echo $row['type']; ?></td>
If your storing multiple values,then use array to do so.Here is the code:
<td><input type="hidden" name="type[]" value="<?php echo $row['type']; ?>"><?php echo $row['type']; ?></td>
In Table.php you can retrieve those values using foreach
like this:
<?php
foreach($_GET['type'] as types)
{
echo types;
}
?>
To get values of radio button, simply use $_GET['region']
in table.php.