I am very new to PHP, so be easy I know it is all bad. I am trying to use values from my DB to populate my progress bar. My connection to DB and everything works but I am not sure how to actually do it. I have tried two separate ways and neither seems to work, please assist me. I know the code is bad but it is just an assignment for class and the quickest and easiest way to get it working is all I need.
Version 1:
<?php
session_start();
include ('inc/session.php');
include ('inc/connect.php');
$query = "select * from user where username='$username'";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_assoc($result);
$que3 = "select * from retirement where userID='$userID' ORDER BY year
DESC, month DESC LIMIT 1";
$result2 = mysqli_query($link, $que3);
$row2 = mysqli_fetch_assoc($result2);
$percent = $row2['balance'] / $row['nestEgg'];
$percent1 = $percent * 100;
echo '<div class="progress">'echo '<div class="progress-bar progress-bar-striped active"
role="progressbar"aria-valuenow="$row['balance']; " aria-valuemin="0"
aria-valuemax="$row['nestEgg']; " style="width:echo '$percent1';"> ';
echo "Keep Saving";
echo '</div>';
echo '</div>';
?>
Version 2:
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
aria-valuenow="
<?php
$que3 = "select * from retirement where userID='$userID' ORDER BY year
DESC, month DESC LIMIT 1";
$result2 = mysqli_query($link, $que3);
$row2 = mysqli_fetch_assoc($result2);
$row['balance'];
?>
" aria-valuemin="0" aria-valuemax="
<?php
$query = "select * from user where username='$username'";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_assoc($result);
$row['nestEgg'];
?>
" style="width:
<?php
session_start();
include ('inc/session.php');
include ('inc/connect.php');
$query = "select * from user where username='$username'";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_assoc($result);
$que3 = "select * from retirement where userID='$userID' ORDER BY year
DESC, month DESC LIMIT 1";
$result2 = mysqli_query($link, $que3);
$row2 = mysqli_fetch_assoc($result2);
$percent = $row2['balance'] / $row['nestEgg'];
$percent1 = $percent * 100;
echo $percent1;
?>
">
Keep Saving
</div>
</div>
It is hard for me to say what the exact issue is without seeing the results of your code. If you make a JSFiddle that would be really helpful. One thing that immediately jumped is in example one the code where you echo out the progress bar is not correct. You need to use '.' to concatenate your variables to your text. See below for correct set up:
echo '<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="' . $row['balance'] . '" aria-valuemin="0" aria-valuemax="' . $row['nestEgg'] . '" style="width:' . $percent1 . '" />';