prendere nomi da database

valient13

Utente Attivo
6 Apr 2012
96
0
0
Sicilia
PHP:
<?php
//-------------- Prendiamo i giocatori dal database --------------------
	
	$sql="SELECT * FROM giocatori WHERE id_utente='$id_utente'";
	$query_sql=mysql_query($sql) or die(mysql_error());
	$query_sql1=mysql_query($sql) or die(mysql_error());
//----------------------------------------------------------------------
?>
				<table>
					<tr>
					<td><div style="padding-bottom: 50px"></td>
					</tr>
					<tr>
						<td>
						<select>
							<option></option>
								<?php
									while ($giocatore_port=mysql_fetch_assoc($query_sql)) {
										echo '<option>'.$giocatore_port['por1'].'</option>';
										echo '<option>'.$giocatore_port['por2'].'</option>';
										echo '<option>'.$giocatore_port['por3'].'</option>';
									}
								?>
						</select>
						</td>
					</tr>
				</table>
				<table>
					<tr>
					<td><div style="padding-bottom: 100px"></td>
					</tr>
					<tr>
						<td>
							<select>
								<option></option>
								<?php
									while ($giocatore_dif=mysql_fetch_assoc($query_sql1)) {
										echo '<option>'.$giocatore_dif['dif1'].'</option>';
										echo '<option>'.$giocatore_dif['dif1'].'</option>';
										echo '<option>'.$giocatore_dif['dif3'].'</option>';
									}
								?>
							</select>
						</td>
						<td></td>
						<td><select><option>Difensore 1</option><option>Difensore 2</option><option>Difensore 3</option></select></td>
						<td></td>
						<td><select><option>Difensore 1</option><option>Difensore 2</option><option>Difensore 3</option></select></td>
						<td></td>
						<td><select><option>Difensore 1</option><option>Difensore 2</option><option>Difensore 3</option></select></td>
					</tr>
				</table>
				<table>
					<tr>
					<td><div style="padding-bottom: 120px"></td>
					</tr>
					<tr>
						<td><select><option>Centrocampista 1</option><option>Centrocampista 2</option><option>Centrocampista 3</option></select></td>
						<td></td>
						<td><select><option>Centrocampista 1</option><option>Centrocampista 2</option><option>Centrocampista 3</option></select></td>
						<td></td>
						<td><select><option>Centrocampista 1</option><option>Centrocampista 2</option><option>Centrocampista 3</option></select></td>
					</tr>
				</table>
				<table>
					<tr>
					<td><div style="padding-bottom: 180px"></td>
					</tr>
					<tr>
						<td><select><option>Attaccante 1</option><option>Attaccante 2</option><option>Attaccante 3</option></select></td>
						<td></td>
						<td><select><option>Attaccante 1</option><option>Attaccante 2</option><option>Attaccante 3</option></select></td>
						<td></td>
						<td><select><option>Attaccante 1</option><option>Attaccante 2</option><option>Attaccante 3</option></select></td>
					</tr>
				</table>

Questa è la tabella:
Codice:
id 	id_utente 	por1 	por2 	por3 	dif1 	dif2 	dif3 	dif4 	dif5 	dif6 	dif7 	dif8 	centro1 	centro2 	centro3 	centro4 	centro5 	centro6 	centro7 	centro8 	att1 		att2 	    att3 	 att4 	       att5 	  att6
18 	6 		buffon 	buffon1 buffon2 maicon 	maicon1 maicon2 maicon3 maicon4 maicon5 maicon6 maicon7 zanetti 	zanetti1 	zanetti2 	zanetti3 	zanetti4 	zanetti5 	zanetti6 	zanetti7 	ibrahimovic ibrahimovic1 ibrahimovic2 ibrahimovic3 ibrahimovic4  ibrahimovic


Come vedete ogni volta per ogni select devo fargli un while, è devo andarci a creare ogni volta una query, un altro metodo c'è?

Come si vede:
campo.jpg
 
Ultima modifica:

Ciao, per estrapolare dei nomi dal db e riempire le select devi per forza fare un ciclo, che sia for o while o foreach, quello che non capisco tu fai un ciclo while e poi metti tante option.
A questo punto o elimini il while o metti una sola option
 

Discussioni simili