Mi stavo chiedendo se non esistesse un qualcosa che permetta di scrivere la funzione genSelect in una forma più semplice.
La funzione gira bene e anzi ogni volta che la utilizzo mi stupisco di quanto sia performante.
Codice PHP:
function genSelect($NomeHTML,$TabDati,$ColID,$ColNome,$Dato = 0,$AttOrdine = 1,$where = ""){
// Nome della select HTML
// Nome Tabella Origine dati
// Nome colonna id
// Nome colonna nome id
// Dato da query
// Attivare ordinamento interno select di default è 1 (quindi attivo)
if (is_numeric($AttOrdine)) {
If ($AttOrdine == 1){ $stringa = " ORDER BY ordine ASC"; }
}
if (is_string($AttOrdine)) {
$stringa = " ORDER BY $AttOrdine ASC";
}
if ($where != "") { $where = " WHERE " . $where . " " ; }
$query = "SELECT * FROM ". $TabDati . $where . $stringa;
$queryformat = mysql_query($query);
$select = "<select name='". $NomeHTML ."'>";
$select = $select . "<option value='0'> Non Impostato </option>";
while ($row_select=mysql_fetch_assoc($queryformat)) {
if (($Dato != 0) AND ($Dato != NULL)) {
if ($Dato == $row_select[$ColID]){
$selected = "selected";
}
}
$select = $select . "<option value='". $row_select[$ColID] ."' $selected>". TagliaStringa($row_select[$ColNome],20) ."</option>";
$selected = "";
}
$select = $select ."</select>";
return $select;
}
Codice PHP:
echo genSelect ('lvlaccount','lvlaccount','id_lvlaccount','tipo',$viewpermessi['id_lvlaccount'],'id_lvlaccount');
Se ho sbagliato sezione in cui postare mi scuso in anticipo, non era mia intenzione promuovere il mio script ma solamente cercare una soluzione simile più performante.