Ver Mensaje Individual
  #7 (permalink)  
Antiguo 05/04/2012, 12:28
Avatar de gjx2
gjx2
 
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: Llenar un Option Box o Combobox desde DB

Copialo tal cual
Código PHP:
Ver original
  1. <?php
  2. /* Me conecto a la base de datos */  
  3.     $hand = mysql_connect("localhost","Ustesteo","Pass")    
  4.     or die("Problemas en la conexion");
  5.     mysql_select_db("DBTest",$hand)  
  6.     or die("Problemas en la seleccion de la base de datos");
  7.  
  8.     /* Query para armar el tag option */  
  9.     $qry = mysql_query("select * from Supers", $hand);  
  10.     $opt="";
  11.     while ($rec = mysql_fetch_array($qry))  
  12.     {  
  13.     /* Armo las opciones del cuadro de selección */  
  14.     if ( $rec["nomsup"] == 1 )  
  15.         $opt .= "<option value=".$rec["nomsup"]." selected>".$rec["dirsup"]."</option>\n";  
  16.     else  
  17.         $opt .= "<option value=".$rec["nomsup"].">".$rec["dirsup"]."</option>\n";  
  18.     }  
  19. echo <<<HTML
  20.     <form method="POST" action="" name="Supers">  
  21.         <select size="1" name="Supers" tabindex="1">  
  22.             "$opt"
  23.         </select><br><br>  
  24. HTML;
  25. ?>