DropDownList e selected value

Pascal Pavan

Nuovo Utente
27 Ago 2012
16
0
0
Ciao ragazzi!
IO ho una form di aggiornamento dati e in un campo della mia tabella voglio fare l'update usando una DropDownList...
come faccio a fargli selezionare il valore che è già presente in quel campo? I dati sono salvati in un DB MySql

Ecco uno spezzone del codice:
if($_REQUEST["op"]=="updateUt" && $_REQUEST["id"] == $fetch->id)//nel caso update ..
{
echo '<tr><form name="upNewUser" method="POST">';
echo '<td><input type="text" name="newCode" value="'.$fetch->code.'" /></td>';
echo '<td><select name="newStatus">
<option value="0" name="0" >0</option>
<option value="1" name="1" >1</option>
<option value="2" name="2" >2</option>
</select></td>';

echo '<td><input type="text" name="newType" value="'.$fetch->type.'" /></td>';
echo '<td width="200"><input type="text" name="newAfmetingen" value="'.$fetch->afmetingen.'" /></td>';
echo '<td width="100"><input type="text" name="newGewicht_en_max_payload" value="'.$fetch->Gewicht_en_max_payload.'" /></td>';
echo '<td><input type="text" name="newKoopjaar" value="'.$fetch->Koopjaar.'" /></td>';
echo '<td><input type="text" name="newVervaldatum" value="'.$fetch->Vervaldatum.'" /></td>';
echo '<td><input type="text" name="newKeuringsdatum" value="'.$fetch->Keuringsdatum.'" /></td>';
echo '<td><input type="text" name="newOnderhoud" value="'.$fetch->Onderhoud.'" /></td>';
echo '<td><input type="text" name="newSchades" value="'.$fetch->Schades.'" /></td>';
echo '<td><input type="text" name="newLeverancier" value="'.$fetch->Leverancier.'" /></td>';
echo '<td><input type="text" name="newFinanciering" value="'.$fetch->Financiering.'" /></td>';
echo '<center><td colspan="2"><input type="submit" value="UpdateContainer" name="UpdateContainer" /></center></td>';
echo "</form></tr>";

Devo modificare la parte rossa in modo che quando clicco su modifica mi lasci come selected value la scelta che c'era già!
Grazie a tutti =)
 

Eliox

Utente Attivo
25 Feb 2005
4.390
3
0
Per questo tipo di select uso qualcosa del genere:
PHP:
echo "<select name=\"id_sel\">\n";
	{
	while($f = $result->fetch_object($sql_sel))
		{
		 if($f->id_sel == $obj->id_sel)
		 {		
		 echo "<option value=\"".$f->id_sel."\" selected>".$f->nome_sel."</option>\n";
		 }else{
		 echo "<option value=\"".$f->id_sel."\">".$f->nome_sel."</option>\n";
		 }
	}
		echo "</select>\n";
	}
 

Pascal Pavan

Nuovo Utente
27 Ago 2012
16
0
0
Per questo tipo di select uso qualcosa del genere:
PHP:
echo "<select name=\"id_sel\">\n";
	{
	while($f = $result->fetch_object($sql_sel))
		{
		 if($f->id_sel == $obj->id_sel)
		 {		
		 echo "<option value=\"".$f->id_sel."\" selected>".$f->nome_sel."</option>\n";
		 }else{
		 echo "<option value=\"".$f->id_sel."\">".$f->nome_sel."</option>\n";
		 }
	}
		echo "</select>\n";
	}

Mmmh, non reisco a capire! Innanzitutto grazie per la risposta!
Non è che potresti farmi vedere come lo implementi nel codice che ho scritto io? Grazie
 
Discussioni simili
Autore Titolo Forum Risposte Data
A [ASP.Net] Dropdownlist ASP.NET 0
M DropDownList HELP ASP.NET 8
R dropdownlist dinamico ASP.NET 0
mythar DropDownList ASP.NET 6
C No database selected Web Server 0
E Mettere come Selected l'opzione di un select option, tramite il dato di una query. Javascript 2
D get the selected text in JavaScript Javascript 9
L Problema option SELECTED PHP 4
Silen select che non rimane selected PHP 3
F how to get value of all selected checkbox? ASP.NET 1
R valore value di un id da passare in chiamata ajax Ajax 3
P Passare contenuto in value. Ajax 1
M Inserire variabile nella value di una hidden PHP 3
V Option value ridenominato jQuery 1
L Bootstrap 4 input ext value HTML e CSS 1
P [MySQL] Type Decimal - Default Value MySQL 0
D Come salvare scelta della select "dinamica" ajax-php? Come dato php o attributo value tag option? Ajax 5
T Ottenere value slection jQuery 1
Trapano [PHP] Campi "Value" "select" PHP 20
filomeni Variabile recuperata nel value Javascript 1
felino [VBScript] Json: catturare un Value dato il suo Nome Visual Basic 1
felino [VBScript] XML Prendere il Value di un childnode attravervo il nome del nodo Visual Basic 0
JackIlPazzo Scraping contenuto menu e relativi data-value? PHP 19
J Errore the value cannot be null or empty ASP.NET 1
otto9due Funzione cambia attributo input value non funziona.. Un aiutino :D Javascript 14
F aggiungere valore option value jQuery 1
F Nascondere option value Javascript 2
L ITSM-9000 the bundle identifier cannot be changed from the current value Sviluppo app per iOS 0
F value di un input text PHP 4
andrea.peo PHP forzare option value di elenco select database Mysql PHP 2
F leggere option value di un form PHP 4
neo996sps Non recupero il value in un select popolato da DB PHP 4
L Problema di invio "value" PHP 1
L Cambiare Value Javascript 4
L riempire l'input file con value? PHP 3
K Assigning the return value of new by reference is deprecated [esyndicat] PHP 1
ivarello Inserire <output> nel Value dell'Input HTML e CSS 0
C Gestire con un elemento DOM il value di un input text Javascript 11
L inviare a database sia valore di value che valore di altro attributo PHP 5
A Inviare Valore di Option diverso dal "value" PHP 14
I problema con cambiamento automatico di value in un input type text Javascript 1
T A non well formed numeric value encountered PHP 8
B Metodo POST prelevare VALUE da tasto SUBMIT PHP 2
S Menù a tendina con "option value" variabili PHP 5
WpStyle validare attributo "value" HTML e CSS 7
M select non deve restituire value Javascript 1
minatore il value PHP 6
L Column count doesn't match value ..... Classic ASP 2
B problema con document.form3.<nome_campo>.value Javascript 1
P Value di un hidden su history.back Javascript 1

Discussioni simili