Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
I am trying to code PHP into a progress bar that uses values from my DB

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>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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 . '" />';
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!