DarkKnight2011 Posted May 7, 2013 Share Posted May 7, 2013 in this case your using a variable that hasn't been defined before, so either your calculate function isn't working or you need to initialise it first, ie. add $calories = 0; near the top of your code before you use it in a calculation Quote Link to comment Share on other sites More sharing options...
farahZ Posted May 7, 2013 Author Share Posted May 7, 2013 (edited) ok, i initialized everything but how to initialize a query?? empty string ddnt work out! string(181) "INSERT INTO caloriescounter (ID, Date, Lunch, Calories) VALUES (111, '05.07.13',',Cucumber without peal', 65) ON DUPLICATE KEY UPDATE Lunch = ',Cucumber without peal', Calories=65" Edited May 7, 2013 by farahZ Quote Link to comment Share on other sites More sharing options...
DarkKnight2011 Posted May 7, 2013 Share Posted May 7, 2013 sorry what do you mean? the query looks ok? I have never used on duplicate key to be honest so not sure about that Quote Link to comment Share on other sites More sharing options...
farahZ Posted May 7, 2013 Author Share Posted May 7, 2013 i told you before that after every action i get a notice .. so i intialized every variable but i dont know how to initizlize this ... $sql = "INSERT INTO caloriescounter (ID, Date, Lunch, Calories) VALUES ($clid, '$date','$foodS', $total) ON DUPLICATE KEY UPDATE Lunch = '$foodS', Calories=$total"; its working fine, its just i'm getting this after its been executed string(181) "INSERT INTO caloriescounter (ID, Date, Lunch, Calories) VALUES (111, '05.07.13',',Cucumber without peal', 65) ON DUPLICATE KEY UPDATE Lunch = ',Cucumber without peal', Calories=65" Quote Link to comment Share on other sites More sharing options...
DarkKnight2011 Posted May 7, 2013 Share Posted May 7, 2013 that is the var_dump($sql) line we added earlier, just remove it, was to try and find out what is happening with the query Quote Link to comment Share on other sites More sharing options...
farahZ Posted May 7, 2013 Author Share Posted May 7, 2013 great !!!i learned a lot from you .. thank you a bunch Quote Link to comment Share on other sites More sharing options...
Solution DarkKnight2011 Posted May 7, 2013 Solution Share Posted May 7, 2013 your welcome mate, could you mark the question as answered, Good luck with the project Quote Link to comment Share on other sites More sharing options...
Barand Posted May 7, 2013 Share Posted May 7, 2013 @farahZ As I said previously, you should normalize your data tables. Also you shouldn't store totals in your tables.You have your food table containing calories +--------+-----------------+----------+ | idfood | food_name | calories | +--------+-----------------+----------+ | 1 | apple | 20 | | 2 | avocado | 320 | | 3 | cheese, cheddar | 240 | | 4 | cucumber | 12 | | 5 | egg | 50 | | 6 | salmon | 120 | | 7 | steak 8oz | 185 | +--------+-----------------+----------+ what you should store for the meals is +-------+--------+------------+-----------+--------+ | idlog | iduser | date_eaten | meal | idfood | +-------+--------+------------+-----------+--------+ | 1 | 111 | 2013-05-07 | breakfast | 1 | | 2 | 111 | 2013-05-07 | breakfast | 3 | | 3 | 111 | 2013-05-07 | lunch | 4 | | 4 | 111 | 2013-05-07 | lunch | 5 | | 5 | 111 | 2013-05-07 | lunch | 6 | +-------+--------+------------+-----------+--------+ When you want the totals, query the tables, EG SELECT fe.meal, SUM(f.calories) as calories FROM food_log fe INNER JOIN food f USING (idfood) WHERE fe.iduser = 111 AND fe.date_eaten = '2013-05-07' GROUP BY meal; +-----------+----------+ | meal | calories | +-----------+----------+ | breakfast | 260 | | lunch | 182 | +-----------+----------+ Quote Link to comment Share on other sites More sharing options...
farahZ Posted May 7, 2013 Author Share Posted May 7, 2013 WOWi will work on that !!!loved the idea !! thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.