passing checkbox data/variables values to another page

Discussion in 'PHP' started by daboss, Feb 18, 2007.

  1. #1
    i need advice on the most efficient way of accomplishing this:

    1. query data from a database table
    2. depending on the number of records found, display all records to the user
    3. at the end of each record displayed, add a checkbox
    4. at the end of the entire page, include a submit button
    5. the 'action' of the form/submit button is another php page
    6. the user can select multiple rows from the display and click the submit buton
    7. at the action php page, i need to know which checkboxes are selected

    the challenge here is that in the display page, the number of records is dynamic.

    any advice at all would be much appreciated. thanks for your time!
     
    daboss, Feb 18, 2007 IP
  2. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #2
    More or less you need something link this in the "first" page:
    echo '<form action="second_page.php" method="post">';
    echo '<table>';
    $query = 'SELECT * FROM table';
    $result = mysql_query($query);
    while ($row = mysql_fetch_assoc($result)) {
      echo '<tr>';
      echo '<td>' . $row['field1'] . '</td>';
      echo '<td>' . $row['field2'] . '</td>';
      echo '<td><input type="checkbox" name="checkboxes[]" value="' . $row['id'] . '"></td>';
      echo '</tr>';
    }
    echo '<tr><td colspan="3" align="center"><input type="submit" value="Submit this form"></td></tr>';
    echo '</table>';
    PHP:
    and in the "second_page.php" you would have an array called "checkboxes" in $_POST:
    print_r($_POST);
    PHP:
    HTH, cheers! :)
     
    picouli, Feb 18, 2007 IP
    daboss likes this.
  3. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok thanks - will try that out.

    anyone else have comments?
     
    daboss, Feb 18, 2007 IP