Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda