如何在循环到HTML时从PHP传递无线电输入类型值


How to pass radio input type value from PHP while loop to HTML?

我在PHP while循环中有一个单选按钮。

我将第一行的值存储在单选按钮的值中。

我需要在HTML a href中传递单选按钮的值。

如何在同一页面中同时使用PHP和HTML传递该值??

我的代码:

index.php

<html>
<body>
  <a href="#" style="margin-left:21px "><img src="images/print_label.png" name="Image3" width="152" height="110" border="0" align="top" style="margin-top:10px"></a>
<?php
    include "db.php";
    require_once "purna_insert_orders_to_ship.php";
    if(isset($_POST['submit']))
    {
    if($_POST['value'] == 'readytoship') {
        // query to get all Fitzgerald records
        $query = "SELECT * FROM orders WHERE status='readytoship'";
    }
    elseif($_POST['value'] == 'readytodispatch') {
        // query to get all Herring records
        $query = "SELECT * FROM orders WHERE status='readytodispatch'";
    } else {
        // query to get all records
        $query = "SELECT * FROM orders";
    }
    $sql = mysql_query($query);
    $num_rows = mysql_num_rows($sql);
    if($num_rows >= 1)
        {
        echo "<div id='showmenu' class='scroll'>";  
        echo "<table id='table_struct' cellspacing='0' cellpadding='1' border='1' width='400' height='30'>
         <tr class='tr_class' bgcolor='white'>
         <td align='center' style='font-weight:bold'> Select </td>
         <td align='center' style='font-weight:bold'> Po Id </td>
         <td align='center' style='font-weight:bold'> Customer Name </td>
         <td align='center' style='font-weight:bold'> quantity </td>
         <td align='center' style='font-weight:bold'> price </td>
         <td align='center' style='font-weight:bold'> status </td>
        </tr>";
        while($row = mysql_fetch_array($sql))
        {
                echo "<tr height='20' data-order_id='".$row['po_id']."'>
                <td align='center'><input type='radio' class='case' name='radio' value='".$row['po_id']."'></td>
                <td align='center'>".$row['po_id']."</td>
                <td align='center'>".$row['customer_name']."</td>
                <td align='center'>".$row['quantity']."</td>
                <td align='center'>".$row['price']."</td>
                <td align='center'>".$row['status']."</td>
                ";
                echo "</tr>";
        }
        echo "</table>";
        echo "</div>";
    }
}
?>
</body>
</html>

有人能帮我吗??

要在锚标记中使用值,您需要调用GET方法,如下所示:

<a href="mypage.php?po_id={row['po_id']}">Click here</a>

但是,由于它位于单选按钮中,您可能需要考虑使用带有提交按钮的HTML表单,而不是锚标记。

如果你想在html ahref中调用这个值,那么你应该也需要一些jquery

首先,你应该在你的单选按钮中回显一些值

<input type="radio"  name="buttonval" id="smallBtn" value="yourvalue"/>

然后在更改单选按钮时,您将触发事件

<script type="text/javascript">
$(document).ready(function()
{
    $("input[name=buttonval]").on('change', function(){
    var $postID = $('input:radio[name=buttonval]:checked').val();
    $postID = "="+$postID;
    });
    $.ajax ({
       type: "GET",
       url: "localhost/ajax/buttonvaluereceiver.php",
       data: {"postID" : $postID }
    });
});
</script>

在ajax调用成功的事件中,您将得到buttonvaluereceiver.php文件执行的结果

更新:

正如你需要立即在单选按钮更改中做的那样,我正在为你更新我的答案

这是html和脚本

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form name='frm' id='frm'>
<input type='radio' id='test' value='rad' name='rad'>
</form>
Your link : 
<div id='link'></div>
<script>
$("input").change(function(){
    var data = $("#frm").serialize();

        Call();        
});
function Call()
    {
        $.ajax({
        type: "POST",
        url : "result.php",
        data : $("#frm").serialize(),
        success : function(data)
        {
        console.log(data);
        $("#link").html(data);
        }
    },"json");
 }
</script>

这是创建链接的php

<?php 
echo "<a href='url.php?id".$_POST['rad']."'>Click here</a>";
?>

您可以根据需要更改url和值。