Zend - The PHP Company




HTML

Add Code


GetCombo  

Type: code fragment
Added by: mindf
Entered: 10/01/2001
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 6010
Combo-BOX - Abstraction With function you can retrieve the combo-box structure with its data.


<?php
function GetCombo_Where($db$nombre$tabla$campo_lista$campo_graba$campo_seleccionado,$valor_seleccionado,$where)
    {
            
$query="SELECT * FROM $tabla ";
        
$query.=($where)?"WHERE ".$where:"";

        
$db -> query ($query);

        
$cant_registros $db -> num_rows ( );

        
$string "<select name=".$nombre.">";
        if (
$seleccionado=="")
              
$string .="<option></option>";

        for (
$i=1;$i<=$cant_registros;$i++)
        {
            
$db -> next_record ( );
            
$value $db -> Record[$campo_graba];

            if (
$valor_seleccionado == $db -> Record[$campo_seleccionado])
                  
$string .= "<option selected value = ".$value." >";
            else
                  
$string .= "<option value = ".$value." >";

            
$string .= $db -> Record[$campo_lista];
            
$string .= "</option>";
        }
        
$string .= "</select>";
        return 
$string;
   }
?>


Usage Example


GetCombo_Where(database,combo name,table,output combo text, combo value, table row selected, table value selected, sql where statement without where clause );


Rate This Script





Search



This Category All Categories