Jump to content


  • Content count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About mal14

  • Rank

Profile Information

  • Gender
    Not Telling
  1. mal14

    How to display SQL Sum query in html?

    Thank you!!! It works
  2. mal14

    How to display SQL Sum query in html?

    I tried doing this! while($row = mysqli_fetch_assoc($result)) { echo 'Calories burned to date: '.$row['calories']; } However, I keep getting any error saying calories is an undefined index
  3. mal14

    How to display SQL Sum query in html?

    No, it's float :/
  4. I've come up with an SQL sum query: $query = "SELECT SUM(calories) FROM tracklog AS calories WHERE userid = $_SESSION[userid]"; No errors are shown, however how do I get this value to be displayed using HTML? I want it to be displayed after 'Total number of calories lost to date:'
  5. Current data for what exactly?
  6. Just gave that a shot! Unfortunately, the progress bar disappears when I do that
  7. 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) ?>
  8. Thank a lot for the advice! It's helped a lot!
  9. 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
  10. I've tried doing this however, it doesn't allow me to store any data into my database anymore
  11. Ohhh I see! So how could we get the calories burned to be against just the latest goal?
  12. The bar now works! This comes up... Calories burned to date : 4218 Target calories : 154000
  13. 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.
  14. 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?
  15. There is a target "weightlost" for that user. I inputted another just to make sure.

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.