I have a table in my database called "client types", with 3 fields: user, type, discount.
Class code Clients :
<?php
/**
* Clase TiposClientes.
*/
class TiposClientes {
private $idusuario;
private $tipo;
private $descuento;
/**
* Constructor de la clase TiposClientes.
* @param type $row
*/
public function __construct($row){
$this->idusuario = $row["idusuario"];
$this->tipo = $row["tipo"];
$this->descuento = $row["descuento"];
}
function getIdusuario() {
return $this->idusuario;
}
function getTipo() {
return $this->tipo;
}
function getDescuento() {
return $this->descuento;
}
function setIdusuario($idusuario) {
$this->idusuario = $idusuario;
}
function setTipo($tipo) {
$this->tipo = $tipo;
}
function setDescuento($descuento) {
$this->descuento = $descuento;
}
function mostrarTiposClientes(){
echo $this->idusuario;
echo $this->tipo;
echo $this->descuento;
}
}
In a .php file I make the queries I want in this case I want to extract all TYPES of client types .
static public function obtenerTiposClientes(){
//Realizamos la consulta.
$ejecucion = self::Conexion();
$registro = $ejecucion->query("SELECT * FROM tiposclientes;");
return $registro;
}
And those guys I want to add them in a combobox (drop-down menu), why do not you load them on the select?
HTML + PHP code to load the "type" in the select:
<label>Tipos: <select name = "tipo">
<?php
$datos = BD::obtenerTiposClientes();
foreach($datos as $x){
echo "<option value='".$x['tipo']."'>".$x['tipo']."</option>";
}
?>
</select>
</label>