sql
php
iphone
css
c
xml
ajax
python
xcode
ruby-on-rails
regex
mysql
silverlight
json
oracle
tsql
asp
api
postgresql
dom
remove your ORDER BY :), so the sql like this :)
SELECT SUM(calories) FROM foods a, user_foods b WHERE a.id = b.foodid AND b.username LIKE '$user' AND b.day='$day' AND b.month LIKE '$month' AND b.year LIKE '$year'
If you are looking for exact match then use equal to operator. Try this query:
SELECT SUM(calories) FROM foods a INNER JOIN user_foods b ON a.id = b.foodid AND b.username LIKE '$user' AND b.day='$day' AND b.month LIKE '$month' AND b.year LIKE '$year'
Since you create an associative array $calories[0] won't work. Give that sum a name in your query and use that as array index.
$calories[0]