cdsatrian

Multiple value

Feb 23rd, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. //--ASALNYA :
  2. $id_siswa ='$_GET[id_siswa]';      
  3. $result = mysql_query("SELECT id_siswa, hobi
  4.                                    FROM tb_siswa
  5.                                    WHERE id_siswa='$id_siswa'");
  6. $array = mysql_fetch_array($result);
  7.  
  8. $sql=mysql_query("SELECT * FROM ms_hobi");
  9. while($row=mysql_fetch_assoc($sql)){
  10. $list_id = explode(",",$array['hobi']);
  11. $id = $row['id_hobi'];
  12.  
  13. foreach ($id as $hobi) {
  14.     if(in_array($id, $hobi)){
  15.         echo '<option value="'.$id.'" selected>'.$row['hobi'].'</option>';
  16.             }   else {
  17.         echo '<option value="'.$id.'">'.$row['hobi'].'</option>';
  18.     } } }
  19.  
  20. //-- DIUBAH MENJADI:
  21. //--
  22. $id_siswa =$_GET[id_siswa];
  23. $result = mysql_query("
  24.     SELECT hobi
  25.     FROM tb_siswa
  26.     WHERE id_siswa='$id_siswa'
  27. ");
  28. $array = mysql_fetch_assoc($result);
  29. $list_id = explode(",",$array['hobi']);
  30. $sql=mysql_query("SELECT * FROM ms_hobi");
  31. while($row=mysql_fetch_assoc($sql)){
  32.     echo "<option value='{$row['id_hobi']}'".(in_array($row['id_hobi'], $list_id)?" selected":"").">{$row['hobi']}</option>";
  33. }
  34. //--
Add Comment
Please, Sign In to add comment