Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--ASALNYA :
- $id_siswa ='$_GET[id_siswa]';
- $result = mysql_query("SELECT id_siswa, hobi
- FROM tb_siswa
- WHERE id_siswa='$id_siswa'");
- $array = mysql_fetch_array($result);
- $sql=mysql_query("SELECT * FROM ms_hobi");
- while($row=mysql_fetch_assoc($sql)){
- $list_id = explode(",",$array['hobi']);
- $id = $row['id_hobi'];
- foreach ($id as $hobi) {
- if(in_array($id, $hobi)){
- echo '<option value="'.$id.'" selected>'.$row['hobi'].'</option>';
- } else {
- echo '<option value="'.$id.'">'.$row['hobi'].'</option>';
- } } }
- //-- DIUBAH MENJADI:
- //--
- $id_siswa =$_GET[id_siswa];
- $result = mysql_query("
- SELECT hobi
- FROM tb_siswa
- WHERE id_siswa='$id_siswa'
- ");
- $array = mysql_fetch_assoc($result);
- $list_id = explode(",",$array['hobi']);
- $sql=mysql_query("SELECT * FROM ms_hobi");
- while($row=mysql_fetch_assoc($sql)){
- echo "<option value='{$row['id_hobi']}'".(in_array($row['id_hobi'], $list_id)?" selected":"").">{$row['hobi']}</option>";
- }
- //--
Add Comment
Please, Sign In to add comment