delete multiple rows using radio buttons

Discussion in 'PHP' started by rapsody, May 20, 2006.

  1. #1
    hi, iam am having problems deleting rows for a db using radio buttons. The below code displays the message names. when the form is posted its suppose to check whether the radio buttons have been checked hten delete the appropiate messages.

    i have put the radio in an array

    where do i go from here.........cheers

    query="SELECT * FROM details";
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    mysql_close();
    ?>

    <center>
    <table width=100% align="center" cellpadding="3" cellspacing="3" >
    <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
    <?
    $i=0;
    echo "<tr><td > <b>name </b> </td>";


    while ($i < $num) {

    $name=mysql_result($result,$i,"name");


    echo "<tr><td > $name </td>";

    echo "<td><input type='radio' name='oldactive[{$row}]' value='{$row[active]}'</td></tr>";
    $i++;
    }

    ?>

    <tr><td><input type="submit" value="submit"></td></tr>
    </form>
    </table>
     
    rapsody, May 20, 2006 IP
  2. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    I can't help with the PHP but the easiest way would be to request the primary key values (which I assume are the radio button values) and execute an SQL statement similar to this....

    DELETE FROM detail WHERE id IN (1,5,7,9)
     
    DanInManchester, May 20, 2006 IP
  3. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #3
    The code and the question is not really clear but I hope this sample may help

    
    <?php
    
    if(isset($_POST[submit])){
    $sql="DELETE FROM details where id ='$_POST[option]'";
    mysql_query($sql) or die(mysql_error());
    }
    
    query="SELECT * FROM details";
    $result=mysql_query($query) or die(mysql_error());
    $myrows=mysql_fetch_array($result) ;
    
    ?>
    
    <center>
    <table width=100% align="center" cellpadding="3" cellspacing="3" >
    <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
    <?
    
    echo "<tr><td > <b>name </b> </td>";
    
    if(mysql_numrows($result) > 0){
    do{
    $name=$myrows[name];
    echo "<tr><td > $name </td>";
    
    echo "<td><input type='radio' name='option' value='$myrows[id]'></td></tr>"; 
    }while($myrows=mysql_fetch_array($result));
    }
    ?>
    
    <tr><td><input type="submit" value="submit" name="submit"></td></tr>
    </form>
    </table>
    
    Code (markup):
     
    PinoyIto, May 22, 2006 IP