Jump to content

[SOLVED] how to calculate


new_php85

Recommended Posts

haii... im new in php....

 

i have table name record (id, location, noofday, rate). i want to do calculation betwen noofday and rate. eg: noofday * rate = amount.

 

this is my example code

 


$q2 = "SELECT noofday * rate AS amount FROM record WHERE id='$id'"; 
$result2 = mysql_query($q2) or die('Query failed. ' . mysql_error()); 

echo $result2

 

but it only appear  Resource id #4. how come ya??? ??? ??? ???

Link to comment
https://forums.phpfreaks.com/topic/123381-solved-how-to-calculate/
Share on other sites

For an explanation, if you look at mysql_query() in the manual it has information about the return value. If you use something like a SELECT then it returns a MySQL Resource if it was successful or false on failure, this is why if you echo the query it will tell you the Resource ID #.

$q2 = "SELECT noofday * rate AS amount FROM record WHERE id='$id'"; 
$result2 = mysql_query($q2) or die('Query failed. ' . mysql_error()); 
$row = mysql_fetch_array($result2);
echo $row['amount'];

 

thank you for your information... :) but why i got nothing for amount

For an explanation, if you look at mysql_query() in the manual it has information about the return value. If you use something like a SELECT then it returns a MySQL Resource if it was successful or false on failure, this is why if you echo the query it will tell you the Resource ID #.

 

thanks again... i got it ;D:D;D

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.