如何使用基于复选框输入的数据回显多行?

时间:2013-09-01 03:45:27

标签: php mysql

试图用基于复选框输入的数据回显多行。从当前代码开始,无论勾选多少个复选框,它都只处理一个复选框中的数据。请帮忙!

while ($row = mysql_fetch_assoc($r)) {
    $pals .= '<input type="checkbox" name="pal_num[]" value="'
        . $row['pal_num'] . '">' . $row['pal_num'] . '<br>';
}

if ($pal == '') {
    echo '';
} else {
    echo '<form name="get_pal" action="post2.php" method="POST">';
    echo $pals;
    echo '<input type="submit" name="post" value="Go!">';
    echo '</form>';
}

post2.php:

$w = $_POST['pal_num'];
$rrr = mysql_query("SELECT * FROM pl_tab WHERE pal_num" . $w[0]);

while ($row = mysql_fetch_array($rrr)) {
    echo '<tr><td>' . '&nbsp' . '</td>';
    echo '<td rowspan="5">' . $row['descr'] . '</td>';
    echo '<td><b>' . 'Total weight' . '<b></td>';
    echo '<td>' . '&nbsp' . '</td><td>' . '&nbsp' . '</td></tr>';

    echo '<td>' . '&nbsp' . '</td>';
    echo '<td colspan="3">' . '&nbsp' . '</td>';

    //this part should multiple based on how many checkboxes are ticked.
    echo '<tr><td>' . $row['l_num'] . '</td>';
    echo '<td>' . $row['pal_num'] . '</td>';
    echo '<td>' . $row['weight 1'] . '</td><td>' . $row['weight 2'] . '</td></tr>';
}
echo "</table>";
}

1 个答案:

答案 0 :(得分:1)

可能会有效:

$w = "'".implode("','",$_POST['pal_num'])."'";
$rrr = mysql_query("SELECT * FROM pl_tab WHERE pal_num in (".$w.");");

...可能您忘记了echo "<table>";之前的while:)