Originariamente inviato da REGISTRAMI
...
Problema: io voglio estrarre (con un ciclo? Quale?) dall'array $row tutte le righe che hanno come "gruppo" il gruppo A, così da poterle mettere in una tabella del gruppo A; lo stesso voglio che venga fatto in sequenza anche per quelle righe del gruppo B e quelle del gruppo C.
Per meglio chiarirmi il risultato che voglio è ottenibile con 3 query diverse, cioè:
Codice PHP:
<?php
/* Estraggo solo gli utenti del GRUPPO A */
$query1 = "SELECT * FROM ciao WHERE gruppo='A'";
$result1 = mysql_query($query)
or die(mysql_error());
?>
<table>
<caption> Gruppo A </caption>
<thead> <th>Nome</th>
<th>Cognome</th>
<th>Gruppo</th>
</thead>
<?php
while($row = mysql_fetch_array($result1))
{ echo "<tbody> <td>" .$row['nome']. "</td>
<td>" .$row['cognome']. "</td>
<td>" .$row['gruppo']. "cent</td>
</tbody>"; }
/* Estraggo solo gli utenti del GRUPPO B */
$query2 = "SELECT * FROM ciao WHERE gruppo='B'";
$result2 = mysql_query($query)
or die(mysql_error());
?>
<table>
<caption> Gruppo B </caption>
<thead> <th>Nome</th>
<th>Cognome</th>
<th>Gruppo</th>
</thead>
<?php
while($row = mysql_fetch_array($result2))
{ echo "<tbody> <td>" .$row['nome']. "</td>
<td>" .$row['cognome']. "</td>
<td>" .$row['gruppo']. "cent</td>
</tbody>"; }
/* Estraggo solo gli utenti del GRUPPO C */
$query3 = "SELECT * FROM ciao WHERE gruppo='C'";
$result3 = mysql_query($query)
or die(mysql_error());
?>
<table>
<caption> Gruppo C </caption>
<thead> <th>Nome</th>
<th>Cognome</th>
<th>Gruppo</th>
</thead>
<?php
while($row = mysql_fetch_array($result3))
{ echo "<tbody> <td>" .$row['nome']. "</td>
<td>" .$row['cognome']. "</td>
<td>" .$row['gruppo']. "cent</td>
</tbody>"; }
?>
Visto che mi sembra inutile fare 3 query diverse, vorrei fare una query sola dove estraggo tutti i dati nell'array mysql_fetch_array, e da lì poi dico:
"per tutte quelle righe che hanno come valore del campo "gruppo" A => crea un array $gruppoA=array(tutte le righe di quelli del gruppo A).
"per tutte quelle righe che hanno come valore del campo "gruppo" B => crea un array $gruppoB=array(tutte le righe di quelli del gruppo B).
"per tutte quelle righe che hanno come valore del campo "gruppo" C => crea un array $gruppoC=array(tutte le righe di quelli del gruppo C)."
Spero di essermi spiegato e di non essere stato confusionario.
Grazie a tutti in anticipo!