mal14 Posted February 16, 2017 Author Share Posted February 16, 2017 This error pops up... Division by zero in /Applications/MAMP/htdocs/FitFab/track.html on line 254 $cal_width = $calories * $width / $target; Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2017 Share Posted February 17, 2017 Could be there is no target "weightlost" in the user's goal record Quote Link to comment Share on other sites More sharing options...
mal14 Posted February 17, 2017 Author Share Posted February 17, 2017 There is a target "weightlost" for that user. I inputted another just to make sure. Quote Link to comment Share on other sites More sharing options...
mal14 Posted February 17, 2017 Author Share Posted February 17, 2017 So I changed the each $target to $target_calories. These are the calories the user has burned: Calories Burned: 876 Calories Burned: 530 And this is the total: Calories burned to date : 4218 So I think the sum calculation may be wrong? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2017 Share Posted February 17, 2017 I get that I've just tried that So the bar comes up and when I enter an activity to find out how many calories are burned(530) and save it to the database... Calories burned to date : Target calories : ^^this comes up and the bar stays blank I get that if the userid in the session data has no data in the tables So I changed the each $target to $target_calories. These are the calories the user has burned: Calories Burned: 876 Calories Burned: 530 And this is the total: Calories burned to date : 4218 So I think the sum calculation may be wrong? Looks like there are 3 goal records for the user. I assumed 1. If there are several, how are they to be processed? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2017 Share Posted February 17, 2017 Here's a replacemnt progress_bar function function progress_bar($width, $height, $calories, $target) { $bar = "<svg width='$width' height='$height' view_box='0 0 $width $height'>\n <rect x='0' y='0' width='$width' height='$height' fill='#CCC' />\n"; // calc width of bar for calories already burned if ($target==0) { $target = 1; } if ($calories > 0) { $cal_width = $calories * $width / $target; $bar .= "<rect x='0' y='0' width='$cal_width' height='$height' stroke='#ccc' fill='#3C3' />\n"; } else { $bar .= "<text x='5' y='16' font-size='9pt'>No data for user</text>\n"; } $bar .= "</svg>\n"; return $bar; } Quote Link to comment Share on other sites More sharing options...
mal14 Posted February 17, 2017 Author Share Posted February 17, 2017 Looks like there are 3 goal records for the user. I assumed 1. If there are several, how are they to be processed? I would like the latest goal set to be the one the user tracks their calories burned against, considering that their previous goal had been met already. Quote Link to comment Share on other sites More sharing options...
mal14 Posted February 17, 2017 Author Share Posted February 17, 2017 (edited) Here's a replacemnt progress_bar function function progress_bar($width, $height, $calories, $target) { $bar = "<svg width='$width' height='$height' view_box='0 0 $width $height'>\n <rect x='0' y='0' width='$width' height='$height' fill='#CCC' />\n"; // calc width of bar for calories already burned if ($target==0) { $target = 1; } if ($calories > 0) { $cal_width = $calories * $width / $target; $bar .= "<rect x='0' y='0' width='$cal_width' height='$height' stroke='#ccc' fill='#3C3' />\n"; } else { $bar .= "<text x='5' y='16' font-size='9pt'>No data for user</text>\n"; } $bar .= "</svg>\n"; return $bar; } The bar now works! This comes up... Calories burned to date : 4218 Target calories : 154000 Edited February 17, 2017 by mal14 Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2017 Share Posted February 17, 2017 I would like the latest goal set to be the one the user tracks their calories burned against, considering that their previous goal had been met already. So there could be old tracklog records for a user that were targetted against a previous goal. At present, the calories burned in these would also be included against the latest goal. Quote Link to comment Share on other sites More sharing options...
mal14 Posted February 17, 2017 Author Share Posted February 17, 2017 Ohhh I see! So how could we get the calories burned to be against just the latest goal? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2017 Share Posted February 17, 2017 You would have to assign log records to a specific goal. So you would store the id of a goal record in each log record. +-----------+ | user | +-----------+ | userid |--+ | name | | | etc | | +-----------+ | | | +----------+ | | goal | | +----------+ | | goalid |---+ +-------<| userid | | | weighloss| | | units | | | whenby | | | etc | | +----------+ | | | +-------------+ | | tracklog | | +-------------+ | | userid | +-------<| goalid | | calories | | etc | +-------------+ Quote Link to comment Share on other sites More sharing options...
mal14 Posted February 17, 2017 Author Share Posted February 17, 2017 I've tried doing this however, it doesn't allow me to store any data into my database anymore Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2017 Share Posted February 17, 2017 Sorry - I have no a crystal ball. 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.