SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Submit button at the bottom of a table?

    I wrote this table:

    HTML Code:
      			echo("<table border='0'>
      				<tr>
     		 		<th width='10' scope='col' align='left' bgcolor='#CCCCCC'>ID</th>
     		 		<th width='100' scope='col' align='left' bgcolor='#999999'>Title</th>
     		 		<th width='100' scope='col' align='left' bgcolor='#CCCCCC'>Category</th>
     		 		<th width='10' scope='col' align='left' bgcolor='#999999'>Delete</th>
      				</tr>
      				<tr>
     		 		<td bgcolor='#CCCCCC'>".$row['id']."</td>
     		 		<td bgcolor='#999999'><a href='".$jbcms->getUrl()."admin/edit.php?id=".$row['id']."'>".$row['newstitle']."</a></td>
     		 		<td bgcolor='#CCCCCC'>".$catrow['name']."</td>
     		 		<td bgcolor='#999999'><input type='checkbox' name='delete' /></td>
      				</tr>
      			</table>");
    I need to put 1 submit button below the table, that finds all the checked boxes, and the $row['id'] they correspond to. How would I do that?
    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?

  2. #2
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want to check one or more rows to delete using PHP? Is that what you want?

    PHP Code:
    echo ('<input type="checkbox" name="delete[]" value="' $row['id'] . '" />');

    // In your php script, $_POST['delete'] will be an array containing the IDs of all rows that were checked. 

  3. #3
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ohhh thanks

    do I have to keep the brackets after "delete"? also, will putting value="'.$row['id'].'" make it have a checkbox and the id? Like:
    [ ] 5
    ?

    If so, is there a way around it?

    Also, do I need to enclose my table with <form method='post' action='$_SERVER['PHP_SELF'>?
    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?

  4. #4
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. No. Yes

    You have to keep the brackets after delete. Only then will PHP take it as an array which is exactly what you want for your task.

    Putting the value="" attribute to the checkbox field will store the ID of the record that you want to delete in the delete[] array. In your PHP script you can loop through the array like this:
    PHP Code:
    foreach ($_POST['delete'] as $row_id)
    {
        
    $sql "DELETE FROM table_name WHERE my_row_id = {$row_id}";
        
    // mysql_query($sql);

    As for enclosing your table with the form tag, that is necessary for you to be able to submit the form


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •