sebatm Posted May 15, 2010 Share Posted May 15, 2010 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 More sharing options...
kenrbnsn Posted May 15, 2010 Share Posted May 15, 2010 The mysql_query function does not return a value, it returns a pointer to the results. You need to use a fetch function such as mysql_fetch_assoc to get the actual values. Ken Link to comment https://forums.phpfreaks.com/topic/201859-mysql-data-math-operation/#findComment-1058793 Share on other sites More sharing options...
sebatm Posted May 15, 2010 Author Share Posted May 15, 2010 Thank's Ken. But is still get an Parse Error for the following row. ($valoare=($i['nrcont']-[$i-1]['nrcont'])*$pret['pret']); I haven't found anything similar on the internet to check the syntax. Sebastian Link to comment https://forums.phpfreaks.com/topic/201859-mysql-data-math-operation/#findComment-1058800 Share on other sites More sharing options...
Mchl Posted May 15, 2010 Share Posted May 15, 2010 You still get it, because you're still using your $pret variable wrong. See examples here -> mysql_query Link to comment https://forums.phpfreaks.com/topic/201859-mysql-data-math-operation/#findComment-1058869 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.