problema ciclo for
-
ciao ragazzi hoh questo problema.mediante il ciclo for metti i valori nella tabella e ora ne vorrei aggiungere un altro per scprrere un altra tabella e mettre i vaolri negli altri campi dlla tabella come faccio?no ci riesco:x

<table width="96%" border="2" cellpadding="0" cellspacing="0" bordercolor="#999999">
<tr><td width="16%"><em><strong>titolo esercizio </strong></em></td> <td width="10%"><em><strong>argomento esercizio</strong></em></td> <td width="19%"><em><strong>nome libro da cui è preso esercizio</strong></em></td> <td width="13%"><em><strong>modalità invio soluzione</strong></em></td> <td width="14%"><em><strong>tipo di scuola </strong></em></td> <td width="14%"><em><strong> anno</strong></em></td> <td width="14%"><em><strong>materia</strong></em></td> <td width="14%"><em><strong>tipo svolgimento richiesto </strong></em></td> <td width="14%"><em><strong>compenso</strong></em></td> <td width="14%"><em><strong>scadenza</strong></em></td> <td width="14%"><em><strong>scelta esercizio </strong></em></td> <td width="14%"><em><strong>scelta esercizi</strong></em></td> <td width="28%"><em><strong>stato esercizio </strong></em></td> </tr><?php
//testare la sessione
echo @$login_err;
if(IsSet($_SESSION['tutor'])){
echo "<p>Benvenuto tutor: ".@$_SESSION['tutor'][0];}else{
echo "<p>Non sei autenticato !";
echo "<br><a href='login.php'>Effettua Login</a>";
}
$usernamen=$_SESSION['tutor'][0];
//Effettuo il controllo dei dati
//$strSQL = "SELECT titoloesercizio FROM esercizio";
$query = "SELECT * FROM esercizio";
$ris=mysql_query($query) or die("Errore nella query:".mysql_error());$numrows = mysql_num_rows($ris);
for($x=0; $x<$numrows; $x++){
//Recupero il contenuto di ogni record rovato
$resrow = mysql_fetch_row($ris);
$idesercizio=$resrow[0];
$idtutor=$resrow[1];
$titoloesercizio = $resrow[2];
$argomentoesercizio= $resrow[3];
$testo= $resrow[4];
$inviosoluzione= $resrow[5];
$stato= $resrow[6];?>
<tr>
<td width="16%"> <? echo $titoloesercizio ; ?></td><td width="10%"> <? echo$argomentoesercizio ?></td> <td width="19%"> <? echo $testo ?></td> <!--<td width="20%"> <a href=./esercizi/<?php echo $titoloesercizio; ?> > leggi esercizio </a></td>--><td width="13%"><? echo $inviosoluzione; ?> </td>
<td width="14%"> </td>
<td width="14%"> </td>
<td width="14%"> </td>
<td width="14%"> </td>
<td width="14%"> </td>
<td width="14%"> </td>
<td width="14%"><a href="./esercizi/<?php echo $titoloesercizio; ?>"><strong><em>leggi esercizio</em></strong></a></td>
<td width="14%">
<form $_POST['action']="<?php print $_SERVER["PHP_SELF"]; ?>" name="form<? echo $x ?>" method="POST"><input name="statoesercizio" type="hidden" value="<?php echo $stato; ?>">
<input name="idesercizio" type="hidden" value="<?php echo $idesercizio; ?>">
<input type="button" name="n" value="Scelgo" onclick="invia(form<? echo $x ?>,form<? echo $x ?>.statoesercizio.value)">
</form>
<?php
$idesercizio = @$_POST['idesercizio'];
$usernamen=$_SESSION['tutor'][0];$query4 = "SELECT * FROM tutor WHERE username ='$usernamen'";
$result4=mysql_query($query4) or die("Errore nella query:".mysql_error());
$row = mysql_fetch_assoc($result4);
$idtutor = $row['idtutor'];$strSQL = "UPDATE esercizio SET statoesercizio='occupato', idtutor='$idtutor' WHERE idesercizio='$idesercizio'"; //echo $strSQL;
mysql_query($strSQL)OR die("Errore nella query1:".mysql_error());?>
<BR>
<td width="28%"><?php echo $stato; ?> </td> </td></tr>
<?php
}?>
</table><?php
echo "<br><a href='homepage.php'>Vai all' homepage </a>";
?> -
Fa una cosa.
RESPIRA.
E ripeti PIANO PIANO il problema, magari stando attento a scrivere, grazie.
-
allora:
col ciclo for che cè nel file scorro quella tabella e metto i valori(in base alla select) nella tabella.
nella tabella ci sn altri campi vuoti che devono essere riempiti con dei valori presi nello stesso modo da un altra tabella.
non so come mettre l'altro ciclo for!il ciclo for da aggiungere è questo:
$query = "SELECT * FROM propone";
$ris=mysql_query($query) or die("Errore nella query:".mysql_error());$numrows = mysql_num_rows($ris);
for($x=0; $x<$numrows; $x++){
//Recupero il contenuto di ogni record rovato
$resrow = mysql_fetch_row($ris); -
-
Sarò limitato io ma non ti seguo

Devi prendere i dati da due tabelle diverse in pratica?
E se sì, son collegate in qualche modo?
Se sì anche ora, come? in che rapporto?
1:1 1:n n:m? Cioè: per ogni dato che prendi dalla prima quanti ne corrispondono nella seconda?Lascia perdere il codice. Spiegati.

-
allora le due tabelle sn legate tra loro
la tab esercizio ha come id: idesercizio
la tab propone ha come id: idesercizio idstudentei valori riesco a recuperarli bene.
solo che col il primo ciclo for prendo i valori e li stampo nella tabella
mentre il secondo ciclo for non so come metterlo -
-
Devi fare una join tra le due tabelle.
Select * from primatabella as A LEFT join secondatabella as B ON A.idutente=B.idutente WHERE ..... ; ad esempio.
In pratica dici:
scegli tutto ciò che c'è nella tabella chiamata primatabella che per semplicità chiamo A, uniscila alla secondatabella che chiamo B usando come regola di unione idutente, uguale per entrambe.Spero di averci beccato

-
credo che la soluizone sia quella.ho scritto cosi:
$query ="Select * from esercizio as A LEFT join propone as B ON A.idesercizio=B.idesercizio"; $ris=mysql_query($query) or die("Errore nella query:".mysql_error()); $numrows = mysql_num_rows($ris); for($x=0; $x<$numrows; $x++){ //Recupero il contenuto di ogni record rovato $resrow = mysql_fetch_row($ris); $idesercizio=$resrow[0]; $idtutor=$resrow[1]; $titoloesercizio = $resrow[2]; $argomentoesercizio= $resrow[3]; $testo= $resrow[4]; $inviosoluzione= $resrow[5]; $stato= $resrow[6]; $numrows1 = mysql_num_rows($ris); for($x=0; $x<$numrows1; $x++){ //Recupero il contenuto di ogni record rovato $resrow = mysql_fetch_row($ris); $tiposcuola=$resrow[3];ma mi stampa solo la prima riga di entrambe le tabelle
forse ma non so come devo impostare anche la clausola WHERE -
-
mi sn accorto di un problema, cioè non mi stampa i valori presi dalla tabella propone.uffa che sbaglio!!!
$query ="Select * from esercizio as A LEFT join propone as B ON A.idesercizio=B.idesercizio"; $ris=mysql_query($query) or die("Errore nella query:".mysql_error()); $numrows = mysql_num_rows($ris); for($x=0; $x<$numrows; $x++){ //Recupero il contenuto di ogni record rovato $resrow = mysql_fetch_row($ris); //questi sono i valori della tabella esrcizio $idesercizio=$resrow[0]; $idtutor=$resrow[1]; $titoloesercizio = $resrow[2]; $argomentoesercizio= $resrow[3]; $testo= $resrow[4]; $inviosoluzione= $resrow[5]; $stato= $resrow[6]; //questi sono i valori della tabella propone $tiposcuola=$resrow[3]; -
prova a mettere al posto dei numeri, il nome del campo.
quindi invece di
$idesercizio=$resrow[0];
metti
$idesercizio=$resrow['idesercizio'];
-
-
-
-
Aggiungi una print dei campi dopo la fetch, da quella capisci come puntare i campi (se non lo capisci posti l'output e te lo diciamo):
$resrow = mysql_fetch_row($ris);
print_r($resrows); -
mi esce questo
( [0] => 63 [1] => 47 [2] => aaaaaaa [3] => aaaaaaa [4] => aaaaaa [5] => email [6] => occupato [7] => 294 [8] => 63 [9] => primaria [10] => 1° [11] => aritmetica [12] => [13] => dettagliato ) aaaaaaa aaaaaaa aaaaaaemail aaaaaaa leggi esercizio
occupato Array ( [0] => 62 [1] => 44 [2] => vvvvvvv [3] => vvvvvvvvv [4] => vvvvvvv [5] => email [6] => occupato [7] => 294 [8] => 62 [9] => primaria [10] => 1° [11] => aritmetica [12] => [13] => dettagliato ) vvvvvvv vvvvvvvvv vvvvvvvemail vvvvvvvvv leggi esercizio
occupato Array ( [0] => 61 [1] => 44 [2] => hhhhhhhhh [3] => hhhhhhh [4] => hhhhh [5] => email [6] => occupato [7] => 294 [8] => 61 [9] => primaria [10] => 1° [11] => aritmetica [12] => [13] => dettagliato ) hhhhhhhhh hhhhhhh hhhhhemail hhhhhhh leggi esercizio
occupato Array ( [0] => 60 [1] => 47 [2] => fffff [3] => fffffff [4] => fffffff [5] => email [6] => occupato [7] => 294 [8] => 60 [9] => primaria [10] => 1° [11] => aritmetica [12] => [13] => dettagliato ) -
-
Allora, i valori tra quadra sono gli indici, gli elementi che hai sono tutti lì, guarda il campo che ti serve e sai che puoi beccarlo utilizzando $resrows seguito dall'indice tra quadre!
-
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi