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 :)
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.