bulfaitelo

funcao selected

Nov 8th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <?php
  2.  
  3. $conect = mysql_connect($host,$user,$senha) or die ("deu merda!!!");
  4. $ok = mysql_select_db("controleexterno",$conect);
  5.  
  6.  
  7.  
  8.  
  9.  
  10.    
  11.     $query ="SELECT * FROM ins_sabores order by sabor";
  12.     $query_comparacao = "SELECT * FROM ins_inscricao_sabores where id_inscricao='40'";
  13.    
  14.    $result = mysql_query($query);
  15.    $result2 = mysql_query($query_comparacao);    
  16.    while ($row=mysql_fetch_array($result, MYSQL_ASSOC))
  17.    {
  18.             $id_drop_sabor = $row['id_sabor'];
  19.             $sabor = $row['sabor'];
  20.            
  21.                 $selected = 1;
  22.                
  23.                
  24.                 while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC))
  25.                 {
  26.                     $id_inscricao = $row2['id_inscricao'];
  27.                     $id_sabor = $row2['id_sabor'];
  28.                                                        
  29.                     if($id_drop_sabor==$id_sabor)
  30.                     {
  31.                         $form_sabor_sorvete.="<option selected='selected' value='$id_drop_sabor'>$sabor</option>";
  32.                         $selected==0;
  33.                     }
  34.                                        
  35.                 }
  36.                
  37.                 if($selected==1)
  38.                     {
  39.                         $form_sabor_sorvete.="<option value='$id_drop_sabor'>$sabor</option>";
  40.                     }
  41.                  
  42.                
  43.            
  44.    
  45.    }  
  46. ?>
  47. <form action="" method="get">
  48. <?php
  49.  
  50.    
  51.  
  52.  
  53. print "<select multiple='multiple' size='12' >";
  54. print $form_sabor_sorvete  ;
  55. print "</select>";
  56. ?>
  57. <input type="submit" />
  58. </form>
Advertisement
Add Comment
Please, Sign In to add comment