通过单选按钮传递数组

Passing array by radio button

所以在网站的这一部分,我正在制作一个编辑人员信息页面,如果搜索到的名字不止一个人,你会得到一个包含所有人员的 table;您选择所需的并在另一页中进行编辑。 我需要传递与所选人员匹配的数组。我不知道如何通过POST在另一个页面中选择数组。这是发送数组的页面代码的一部分:

$squery=mysqli_query($conn,"SELECT * FROM amico WHERE (Nome= '" .
    $nome . "') AND (Cognome ='" .$cognome. "')");
$num = mysqli_num_rows($squery);
$i=0;
$array= array();
while($rowa=mysqli_fetch_assoc($squery)){
    $array[$i]=$rowa;
    $i++;
}
$ssquery=mysqli_query($conn,"SELECT * FROM amico WHERE (Nome= '" .
    $nome . "') AND (Cognome ='" .$cognome. "')");
if($num > 1) {

    echo 'Trovato più di un elemento';
    echo '<table border="1">';
    echo     '<tr>';
    echo         '<td><p>S</p></td>';
    echo         '<td><p>Nome</p></td>';
    echo         '<td><p>Cognome</p></td>';
    echo         '<td><p>Citt&agrave</p></td>';
    echo     '</tr>';

    $i=0;
    echo   '<form method="POST" action="moficatr.php">';
    while ($row = mysqli_fetch_array($ssquery)) {
        echo '<tr>';
        echo     '<td> <p> <input type="Radio" name="persona" value="'.
            $rowa[$i] . '"></p></td>';
        echo     ' <td><p>' .$row['Nome'] .  '</p></td>';
        echo     '<td><p>'.$row['Cognome'].'</p></td>';
        echo     '<td><p>'.$row['Citta'].'</p></td>';
        echo '</tr>';
        $i++;

    }

    echo '</table>';
    echo '<br><br><input type="submit" value="Modifica"></form>';
}

您只需将所选用户的 ID 传递到下一页,然后使用该页面的 ID 获取所有详细信息,而不是将整个数据数组发送到另一端。

为什么要在代码中执行两次相同的查询?您只需要一个查询即可为您提供所有数据。 另外,我强烈建议您使用 PDO - http://php.net/manual/en/book.pdo.php 或者至少 MySQLi 也支持准备好的语句

$ssquery=mysqli_query($conn,"SELECT * FROM amico WHERE (Nome= '" .
    $nome . "') AND (Cognome ='" .$cognome. "')");
$num = mysqli_num_rows($ssquery);

if($num > 1) {

    echo 'Trovato più di un elemento';
    echo '<table border="1">';
    echo     '<tr>';
    echo         '<td><p>S</p></td>';
    echo         '<td><p>Nome</p></td>';
    echo         '<td><p>Cognome</p></td>';
    echo         '<td><p>Citt&agrave</p></td>';
    echo     '</tr>';

    echo   '<form method="POST" action="moficatr.php">';
    while ($row = mysqli_fetch_assoc($ssquery)) {
    echo '<tr>';
    echo '<td> <p> <input type="Radio" name="persona" value="'.
    $row['id'] . '"></p></td>'; //you can change 'id' with your column name if it's different
    echo     ' <td><p>' .$row['Nome'] .  '</p></td>';
    echo     '<td><p>'.$row['Cognome'].'</p></td>';
    echo     '<td><p>'.$row['Citta'].'</p></td>';
    echo '</tr>';
    $i++;

}

moficatr.php

//Set up a Mysql connection.

$user_id = (int) $_POST['persona'];
//Query the db to fetch all the details of this user.
$query = "SELECT * from your_table where id=?";

//Prepare statment and execute.
$stmt = mysqli_prepare($connection, $query);
mysqli_stmt_bind_param($stmt, "i", $user_id);
mysqli_stmt_execute($stmt);

/* bind result variables */
mysqli_stmt_bind_result($stmt, $name, $address,...);
echo $name;
echo $address;