venance haule

venance haule

  • NA
  • 10
  • 1.1k

I'm trying to edit a multiple select option value

Feb 28 2017 5:18 AM
  1. In the database the value are in this format 1,6,7 but i fail to retrieve them into select menu, i have two query, i pass variable rows from the first query where i have specified select query which fetch data from database by using group_reg_no and i use that variable rows in the second query so that i can get specific activity selected

       
    1. <?php require_once ("db_connection.php");  
    2. if(isset($_GET['edit_id'])) {     
    3.     $edit_sql = "SELECT * FROM group_details WHERE group_reg_no = '$_GET[edit_id]'";  
    4.     $run_sql = mysqli_query($connection$edit_sql);  
    5.     while ($rows = mysqli_fetch_assoc($run_sql)){  
    6.      $group_name = $rows['group_name'];  
    7.      $group_reg_no = $rows['group_reg_no'];  
    8.      $leader_name = $rows['leader_name'];  
    9.      $leader_contact = $rows['leader_contact'];  
    10.      $region = $rows['region'];  
    11.      $district = $rows['district'];  
    12.      $division = $rows['division'];  
    13.      $ward = $rows['ward'];  
    14.      $village = $rows['village'];  
    15.      $activity = $rows['activity'];  
    16.      $category = $rows['category'];  
    17.      $men = $rows['men'];  
    18.      $women = $rows['women'];  
    19.      $total = $rows['total'];  
    20.                       
    21.   
    22.        
    23. }  
    24. }  else  {  
    25.     $group_name = '';  
    26.      $group_reg_no = '';  
    27.      $leader_name = '';  
    28.      $leader_contact = '';  
    29.      $region = '';  
    30.      $district = '';  
    31.      $division = '';  
    32.      $ward = '';  
    33.      $village = '';  
    34.      $activity = '';  
    35.      $category = '';  
    36.      $men = '';  
    37.      $women = '';  
    38.      $total = '';  
    39.       
    40. }  
    41.   
    42. ?>  
  2.                 <label for="activity" class="col-sm-2 control-label">Shughuli za Kikundi</label>  
  3.                 <div class="col-sm-3">  
  4.                      <select class="form-control" name="activity[]"   id="activity" multiple="multiple">  
  5.                      <option value="">Select Activity</option>  
  6.                          <?php  
  7.                         $sel_activity = "SELECT * FROM activity";  
  8.                         $run_activity = mysqli_query($connection$sel_activity);  
  9.                         while($rows = mysqli_fetch_assoc($run_activity)){  
  10.                             $array =  explode(','$rows);  
  11.                             foreach ($array as $rows) {  
  12.                             if($activity == $rows['id']){  
  13.                                 $selected = 'selected';  
  14.                             } else {  
  15.                                 $selected = '';  
  16.                         }  
  17.                         echo '<option value="'.$rows['id'].'" '.$selected.'>'.$rows['activity'].'</option>';  
  18.                             }  
  19.                         }  
  20.                         ?>  
  21.                       
  22.                      </select>  
  23.                 </div>  
  24.                 </div>