
mal14
Members-
Posts
29 -
Joined
-
Last visited
Everything posted by mal14
-
How to make progress bar focus on most recent value set?
mal14 replied to mal14's topic in PHP Coding Help
Current data for what exactly? -
How to make progress bar focus on most recent value set?
mal14 replied to mal14's topic in PHP Coding Help
Just gave that a shot! Unfortunately, the progress bar disappears when I do that -
I'm in the middle of producing a calories tracker. My users can set weight loss goals and then use the exercise calorie calculator to find out how many calories they've lost from particular exercises. I've produced a progress bar to show users their progress, however the progress bar does this for all of the users goals combined, not the most recent goal set. How could I set my progress bar to focus on just the most recent goal set by the user? This is what I have so far <?php $con=mysqli_connect("localhost","root","password","registration"); if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error()); } $bar_length = 500; $bar_height = 40; $sql = "SELECT SUM(calories) as calories , CASE g.weightunit WHEN 'lbs' THEN 3500 ELSE 7700 END * weightlost as target_calories FROM goal g INNER JOIN tracklog t USING (userid) WHERE userid = ?"; $stmt = $con->prepare($sql); $stmt->bind_param('i', $_SESSION['userid']); $stmt->execute(); $stmt->bind_result($calories, $target); $res = $stmt->fetch(); function progress_bar($width, $height, $calories, $target) { $bar = "<p style='padding-left: 30px'>"."<svg width='$width' height='$height' align='center' view_box='0 0 $width $height'>\n <rect x='0' y='0' width='$width' height='$height' align='right' 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' align='center' width='$cal_width' height='$height' stroke='#ccc' fill='#55d5e7' />\n"; } else { $bar .= "<text x='5' y='16' align='center' font-size='9pt'>No data for user</text>\n"; } $bar .= "</svg>\n"; return $bar; } mysqli_close($con); ?> <p align="center" class="font-3" style="font-size: 16px"><br><br >Calories burned to date : <?=$calories?><br> Target calories : <?=$target?><br> <?= progress_bar($bar_length, $bar_height, $calories, $target) ?>
-
Thank a lot for the advice! It's helped a lot!
-
I'm trying to allow my users to edit their profile information. I've made an attempt at it and have this code so far... edit.html page <?php session_start(); ?> <!DOCTYPE html> <html> <head> <title>Login</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="header"> </div> <section id="edit" > <div id="edit"> <b>Edit your Profile</b> <br><br> Please enter your details below to update your profile. <br><br> <form method="post" action="editprofile.php" name="editform" id="editform"> <table width=700px border=0 cellspacing=10><tr><td valign=top><table border=0> <b>Required Information:</b><br><br> <tr><td> <b>Username:</b> </td><td> <?php echo($_SESSION["username"]); ?> </td></tr><tr><td> <b>Email Address:</b> </td><td> <input type="text" name="email" value="<?php echo $email; ?>"> </td></tr></table></td><td valign=top> <table border=0> <b>Optional Information:</b><br><br> <tr><td> <b>Gender:</b> </td><td> <input type="text" name="gender" id="gender" value="<?php echo $gender; ?>"> </td></tr><tr><td> <b>dob:</b> </td><td> <input type="text" name="dob" id="dob" value="<?php echo $dob; ?>"> </tr></td><tr><td valign=top> <b>height:</b> </td><td> <input type="text" name="height" id="height" value="<?php echo $height; ?>"> </td></tr></td> </table> </td></tr> </table> <input type="submit" name="register" id="register" value="Update" class=btn /> </form> </div> </form> </body> </html> editprofile.php page <?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['userid'])) { $nameuser = $_SESSION['userid']; $checkinfo = query("SELECT * FROM users WHERE id = $_SESSION[userid]"); $result = mysqli_query($con, $query); while($results = mysql_fetch_array($checkinfo,MYSQL_ASSOC)){ $id = $results['userid']; $username = $results['username']; $email = $results['email']; $gender = $results['gender']; $dob = $results['dob']; $height = $results['height']; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $editEMAIL=$_POST['email']; $editgender=$_POST['gender']; $editdob=$_POST['dob']; $editheight=$_POST['height']; $editusername=$_POST['username']; $editquery = mysql_query("UPDATE users SET Email='$editEMAIL' , gender='$editgender', dob='$editdob', height='$editheight' WHERE username='$editusername'"); if($editquery == true) { echo "<b>Success!</b>"; echo "Your profile was successfully updated. Please click<a href=\"viewprofile.php\"> here </a>to view."; } else { echo "<b>Error</b>"; echo "<p>Sorry, your profile update failed. Please go back and try again.</p>"; } } } ?> However, I keep getting these errors but I'm not sure why PHP Notice: Undefined variable: email in /Applications/MAMP/htdocs/FitFab/edit.html on line 65 PHP Notice: Undefined index: gender in /Applications/MAMP/htdocs/FitFab/edit.html on line 72 PHP Notice: Undefined variable: dob in /Applications/MAMP/htdocs/FitFab/edit.html on line 76 PHP Notice: Undefined variable: height in /Applications/MAMP/htdocs/FitFab/edit.html on line 80
-
When I do that these errors come up... PHP Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in /Applications/MAMP/htdocs/FitFab/track.html on line 244 PHP Fatal error: Uncaught Error: Call to undefined function progress_bar() in /Applications/MAMP/htdocs/FitFab/track.html:249 Stack trace: #0 {main} thrown in /Applications/MAMP/htdocs/FitFab/track.html on line 249 Line 249: echo progress_bar($bar_length, $bar_height, $calories, $target);
-
This error comes up... PHP Fatal error: Uncaught Error: Cannot pass parameter 2 by reference in /Applications/MAMP/htdocs/FitFab/track.html:244 Stack trace: #0 {main} thrown in /Applications/MAMP/htdocs/FitFab/track.html on line 244 That refers to this line: $stmt->bind_param('i', '$_SESSION[userid]');
-
<?php $con=mysqli_connect("localhost","root","password","registration"); if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error()); } $userid = $_SESSION[userid]; $bar_length = 400; $bar_height = 20; $sql = "SELECT SUM(caloriesburned) as calories_burned , CASE g.weightunit WHEN 'lbs' THEN 3500 ELSE 7700 END * weightlost as target_calories FROM goal g INNER JOIN tracklog t USING (userid) WHERE userid = $_SESSION[userid]"; $stmt = $pdo->prepare($sql); $stmt->execute( [$userid] ); $res = $stmt->fetch(); echo progress_bar($bar_length, $bar_height, $res['calories'], $res['target_calories']); mysqli_close($con); ?>
-
Well, I'm planning to set the weight units, as: 1 lb = 3,500 calories 1 kg = 7,700 calories (^^ I'm unsure how to set these values) From the activity and the time the user enters, the number of calories burned from that activity will be calculated. Then I can take this value away from their set goal.
-
Yeah that's right! I want the progress bar to show the shaded part to be the calories burned and the rest of the bar to be blank which represents the total lbs or kgs wanted to be worked off by the user. I have all the data stored on my database - so the calories burned after each exercise and the weight wanting to be lost by each user in either lbs or kg.
-
I'm making a calories burned calculator which links to goals the user has made. I want to create a progress bar that updates when the user clicks a button that shows how many calories the user has yet to burn in order for them to reach their goal. I've stored the amount of calories burned for each activity the user inputs. The users goals are set in either lbs or kg, so I'm not sure how I can set a value for these units. Also, I'm not sure how I should calculate the calories left to burn. I've looked online, however can't find anything that relates to how to made a progress bar with data from an sql database. Database: 'registration' Table: 'tracklog' and 'goal' Any help would be much appreciated!!!