Jump to content
php.lv forumi

Saskaitiishana


sfx

Recommended Posts

$query = "SELECT * FROM `tab`";
$result = mysql_query($query);
while($dati = mysql_fetch_row($result)){
echo"$dati[1] - $dati[2]":
}

 

$dati[2] ir kautkaadi skaitlji, kaa lai tos saskaita un dabuuju summu.

Link to comment
Share on other sites

MySQL ir tāda lieliska funkcija kā SUM();. kura saskaita uzreiz visu kolonnu.

Piemēram:

--------------------------

|Vards | kukuļi_maize|

--------------------------

|Jānis | 3 |

|Ilze | 1 |

|Laima | 5 |

----------------------------

 

SELECT SUM(kukulji_maize) as summa FROM tabula

 

Bet vari jau arii kā biji sācis.

 

$summa = '';
$query = "SELECT * FROM `tab`";
$result = mysql_query($query);
while($dati = mysql_fetch_row($result)){
echo"$dati[1] - $dati[2]":
$summa .= $summa + $dati[2];
}

Link to comment
Share on other sites

Es izdariiju shadi:

$summa = '';
$query = "SELECT * FROM `tab`";
$result = mysql_query($query);
while($dati = mysql_fetch_row($result)){
echo"$dati[1] - $dati[2]":
$summa .= $summa + $dati[2];
}
print"$summa";

 

Rezultaataa [print"$summa";] bija kautkas nesakariigs, skaitlju rinda [3710722337110682 ] kura nebija summa bet gan ieprieksheejais rezultaas plus naakoshais rezultaats:

3710

72233

7110682

Kas nav pareizi?

Link to comment
Share on other sites

×
×
  • Create New...