ma come si fa a sommare questi due dati?
ho una tabella dove vengono stampati dei numeri presi dal db, come faccio ad avere il totale di quei numeri?<?=$row['voto1']?> + <?=$row['voto2']?>
ma come si fa a sommare questi due dati?
ho una tabella dove vengono stampati dei numeri presi dal db, come faccio ad avere il totale di quei numeri?<?=$row['voto1']?> + <?=$row['voto2']?>
Per esempio
Nel recordset estratto avrai una colonna ($row['somma']) che ha per vaolre voto1+voto2 per l'utente con id = 1codice:SELECT (voto1 + voto2) AS somma FROM tabella WHERE id_utente = 1
<´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
"The answer to your question is: welcome to tomorrow"
forse ho capito quello che vuoi dire, così va bene?
<?php
SELECT (voto1 + voto2) AS somma FROM tabella WHERE id_utente = 1
SELECT (voto1 + voto2) AS somma FROM tabella WHERE id_utente = 1
$somma=$numero1+$numero2;
$frase1="voto 1: ";
$frase2="voto 2: ";
$frase3=", somma dei 2 voti:";
print("$frase1 $numero1 $frase2 $numero2 $frase3 $somma .");
?>
PS: fai uso dei tag giusto e della sintassi corretta:
<? ?> NO
<?php ?> SI'
=$row['blabla'] NO
echo($row['blabla']); SI'
ne va della compatibilità futura e della sicurezza in generale.
<´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
"The answer to your question is: welcome to tomorrow"
così è giusto?:
<?php
SELECT ($numero1 + $numero2) AS somma FROM tabella WHERE id_utente = 1
$somma=$numero1+$numero2;
print("$somma");
?>
Originariamente inviato da prinzart
forse ho capito quello che vuoi dire, così va bene?
codice:<?php SELECT (voto1 + voto2) AS somma FROM tabella WHERE id_utente = 1 SELECT (voto1 + voto2) AS somma FROM tabella WHERE id_utente = 1 $somma=$numero1+$numero2; $frase1="voto 1: "; $frase2="voto 2: "; $frase3=", somma dei 2 voti:"; print("$frase1 $numero1 $frase2 $numero2 $frase3 $somma ."); ?>
E' un po' pasticciato... basterebbe
codice:<?php $query = "SELECT *, (voto1 + voto2) AS somma FROM tabella WHERE id_utente = '1'"; $result = mysql_query($query, $db); while ($row = mysql_fetch_array($result)) { echo("Studente : ".$row['nome_studente']." "); echo("Voto 1: ".$row['voto1']." "); echo("Voto 2: ".$row['voto2']." "); echo("Somma dei voti: ".$row['somma']." "); }
<´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
"The answer to your question is: welcome to tomorrow"
Mi inginocchio al tuo cospetto mio dio![]()
Grazie grazie grazie Andrea1979 sei stato grande!
![]()
questo è lo script che ho realizzato basandomi su quello che mi hai detto per fare la somma dei voti del primo giorno di esame:
e funziona alla grande!<?php
$query = "SELECT *, (attitudine1_giorno1 + tip1_giorno1 + limatura1_giorno1 + gel1_base + lav_finito1_giorno1) AS somma1_giorno1 FROM schedario WHERE id=$allievo";
$result = mysql_query($query, $conn);
while ($row = mysql_fetch_array($result)) {?>
<td align="center" bgcolor="#D3D3D3"><span class="testo_viola_bold"><?=$row['somma1_giorno1']?></span></td>
<?
}
?>
ora vorrei fare una media tra il primo giorno e il secondo giorno. Pensavo di fare (totale voti giorno 1) + (totale voti giorno 2) = (totale 3) : (2 giorni) = (media voti) e pensavo di fare così, però non funziona, dove sbaglio?:
<?php
$query = "SELECT *, (somma1_giorno1 + somma2_giorno2 = somma3 / 2) AS somma_media_totale FROM schedario WHERE id=$allievo";
$result = mysql_query($query, $conn);
while ($row = mysql_fetch_array($result)) {?>
<td align="center" bgcolor="#D3D3D3"><span class="testo_viola_bold"><?=$row['somma_media_totale']?></span></td>
<?
}
?>
non serve l'uguale:
SELECT *,(voto_1 + voto_2 +... +voto_n) / n AS media_voti ....
<´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
"The answer to your question is: welcome to tomorrow"
ho fatto così:
però mi da questo errore:<?php
$query = "SELECT *, (somma_giorno1 + somma_giorno2) / n AS media_voti FROM schedario WHERE id=$allievo";
$result = mysql_query($query, $conn);
while ($row = mysql_fetch_array($result)) {?>
<td align="center" bgcolor="#D3D3D3"><span class="testo_viola_bold"><?=$row['media_voti']?></span></td>
<?
}
?>
sulla linea 428 ho questo:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /web/htdocs/www.sito.it/home/include_elenco_schedario.php on line 428
dove ho sbagliato?while ($row = mysql_fetch_array($result)) {?>