0

Got stuck trying to echo out multiple rows with data based on checkbox input. As of current code it processes data from only one checkbox, no matter how many checkboxes are ticked. Please help!

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
  • Make sure you sanitize $w[0] with mysql_real_escape_string() (and maybe switch to a more modern database API like mysqli or PDO) Commented Sep 1, 2013 at 9:24

1 Answer 1

0

May be this will work :

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

...and may be you forgot a echo "<table>"; before the while :)

Sign up to request clarification or add additional context in comments.

1 Comment

after some tweaking it worked! thank you for helping out a newbie :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.