Jump to content

mysql data math operation


sebatm

Recommended Posts

hi, i'm currently learning php and i need some help.

 

i want to make some math operations with some data from an mysql table, and printing the result.

 

the operation is simple [x-(x-1)]*y but i didn't manage to write it properly.

there are two columns

x - the current read number from col2

(x-1) - the previous read number from col2

y - number from the same row as the (x-1) number, but from a diferent column (col1).

 

i made the mysql connection and the printing, i got in trouble with this part.

 

here is what i wrote:

for($temp[$i] = mysql_query('SELECT nrcont FROM con_apa_rece'); ;$temp[$i++]) 
{
$pret= mysql_query('SELECT pret FROM con_apa_rece');
 ($valoare=($temp[$i]['nrcont']-$temp[$i-1]['nrcont'])*$pret['pret']);
	if($valoare<'0')
		echo "Nu exista inreg anterioara";
	else
		echo $valoare;
}

 

 

can someone help?

 

thank you,

Link to comment
https://forums.phpfreaks.com/topic/201859-mysql-data-math-operation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.