dimanche 19 juillet 2015

select checkboxes to edit only selected values for radio buttons from MySql

I need to update the radio button values based upon the selection of multiple checkboxes using php.I am able to retrieve value for only one selected radio button, when I select more than one checkbox then I am getting value of 1 radio button only and empty values for remaining other radio buttons.Please look at my code. thank you.

    /* news-multi-edit.php */
    <form action="news-multi-edit-save.php" method="post">  
   <?php
   $id1=$_POST['checkbox'];
   $N = count($id1);
   for($i=0; $i < $N; $i++)
   {
  $result = mysql_query("SELECT * FROM news where id='$id1[$i]'");
  while($row1 = mysql_fetch_array($result))
  {
   $id=$row1['id'];  
   $topnews=$row1['topnews'];
     ?>
   <label>Top News</label>
   <label>
    <input type="radio" name="topnews[]" value="1" id="topnews_0"  <?php echo($topnews=='1')?'checked':' '?> />Yes</label>
   <label>
    <input name="topnews[]" type="radio" id="topnews_1" value="0" <?php echo($topnews=='0')?'checked':' '?> />No</label>
    <?php
    }
   } ?>

    /*news.php*/
    <?php
    $sql= "SELECT * FROM news";
    $query=mysql_query($sql);
    $count=mysql_num_rows($query);
    while($nt=mysql_fetch_array($query)){
    ?>
    <input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $nt['id']; ?>" />
    <?php
    }
    ?>




Aucun commentaire:

Enregistrer un commentaire