简体   繁体   中英

Progress bar php and mysql

I need to build progress bar next to the names of people showing how many costumers each people have working for him. When you see the code you will understand my problem. I dont know how to build this.

Just before end of body, before script tags i have progress bar and var that show's names from db. I need to show that names and beside them progress bar with percentage of costumers.

this are my tables 在此处输入图片说明在此处输入图片说明

<?php

if (isset($_GET['poslovni_korisnici'])) {
$active1 = 'class="active"';
}
else {
$active1 = '';
}
if(isset($_GET['korisnici'])) {
$active2 = 'class="active"';
}
else {
$active2 = '';
}

/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'root';

/*** mysql password ***/
$password = '';

try {
$dbh = new PDO("mysql:host=$hostname;dbname=zadatak1", $username, $password);
/*** echo a message saying we have connected ***/
/**echo 'Connected to database';**/
}
catch(PDOException $e)
{
echo $e->getMessage();
}

echo'
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Statistika</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">

    <!-- DataTables CSS -->
    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css">

    <!-- jQuery -->
    <script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>

    <!-- DataTables -->
    <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesnt work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>

    <nav class="navbar navbar-default">
    <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="index.php">POSLOVNA STATISTIKA</a>
    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
    <ul class="nav navbar-nav">
    <li ' . $active1 . '><a href="index.php?poslovni_korisnici">Poslovni korisnici <span class="sr-only">(current)</span></a></li>
    <li ' . $active2 . '><a href="index.php?korisnici">Korisnici</a></li>
    </ul>
    </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
    </nav>';

    switch (isset($_GET)) {
      case isset($_GET['poslovni_korisnici']):

        echo'
        <h1>Poslovni korisnici</h1>

        <a href="unos.php?unosPoslovni"><button type="button" class="btn btn-default btn-sm">Unos</button></a>
        </br>
        </br>';        

        echo'
        <table id="table_id" class="display">
            <thead>
                <tr>
                  <th>Partner id</th>
                  <th>Partner name</th>
                  <th>Partner street</th>
                  <th>Partner zip</th>
                  <th>Partner city</th>
                  <th>Partner country</th>
                </tr>
            </thead>
            <tbody>';

            $sql = "SELECT * FROM poslovni_partneri";

            foreach ($dbh->query($sql) as $row)
            {
                echo'
                <tr>
                    <td>'.$row['Partner_id'].'</td>
                    <td>'.$row['Partner_name'].'</td>
                    <td>'.$row['Partner_street'].'</td>
                    <td>'.$row['Partner_zip'].'</td>
                    <td>'.$row['Partner_city'].'</td>
                    <td>'.$row['Partner_country'].'</td>
                </tr>';
            }

            echo'    
            </tbody>
        </table>';

        break;
      case (isset($_GET['korisnici'])):

        echo'
        <h1>Korisnici</h1>

        <a href="unos.php?unosKorisnici"><button type="button" class="btn btn-default btn-sm">Unos</button></a>
        </br>
        </br>

        <table id="table_id" class="display">
            <thead>
                <tr>
                  <th>User id</th>
                  <th>Partner ID</th>
                  <th>User name</th>
                  <th>User department</th>
                  <th>User email</th>
                  <th>User phone</th>
                  <th>User mobile</th>
                </tr>
            </thead>
            <tbody>';

                $sql = "SELECT * FROM korisnici
                        INNER JOIN poslovni_partneri
                        ON korisnici.Partner_id=poslovni_partneri.Partner_id";

                foreach ($dbh->query($sql) as $row)
                {

                  echo'
                  <tr>
                    <td>'.$row['User_id'].'</td>
                    <td>'.$row['Partner_id'].'</td>
                    <td>'.$row['User_name'].'</td>
                    <td>'.$row['User_department'].'</td>
                    <td>'.$row['User_email'].'</td>
                    <td>'.$row['User_phone'].'</td>
                    <td>'.$row['User_mobile'].'</td>
                  </tr>';

                }

            echo'    
            </tbody>
        </table>';

        break;
      default:

        $sql = "SELECT Partner_name FROM poslovni_partneri";

        $del = $dbh->prepare('SELECT * FROM poslovni_partneri');
        $del->execute();
        $count = $del->rowCount();

        $del = $dbh->prepare('SELECT * FROM korisnici');
        $del->execute();
        $count2 = $del->rowCount();


        echo '<div class="panel panel-primary">
                <div class="panel-heading">Popis poslovnih partnera</div>
                <div class="panel-body">

                  <button class="btn btn-primary" type="button">
                    Broj poslovnih korisnika <span class="badge">'.$count.'</span>
                  </button>
                  </br>
                  </br>
                  <button class="btn btn-primary" type="button">
                    Broj korisnika <span class="badge">'.$count2.'</span>
                  </button>
                  </br>
                  </br>
                  <div class="panel panel-primary">
                  <div class="panel-heading">Popis poslovnih partnera <p class="text-center">Ukupni udio</p></div>
                  <ul class="list-group">';

                    foreach ($dbh->query($sql) as $row)
                    {

                    echo'  
                    <li class="list-group-item list-group-item-info">
                      <span class="badge">144</span>
                      <div class="progress">

                        <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:%">

                          <span class="sr-only">40% Complete (success)</span>
                        </div>
                      </div>
                      <h4 class="names">'.$row['Partner_name'].'</h4>       
                    </li>';

                    }

                  echo'  
                  </ul>

                </div>
              </div>';

        break;
    }

    echo'
    <script>
      $(document).ready( function () {
          $("#table_id").DataTable();
      } );
    </script>

    <!-- jQuery (necessary for Bootstraps JavaScript plugins) -->
    <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>';

?>

You should first get count of customers of each people. Now on basis of number of customers build your progress bar.

Step 1. Get count of customers.

//add your logic here
$customer_count=<for_exampe_its_20>

Step 2. Now on basis of count display your progress bar

<div class="progress">
  <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<? php echo ($customer_count) ?>" aria-valuemin="0" aria-valuemax="100" style="width: <? php echo ($customer_count) ?>%">
    <span class="sr-only"><? php echo ($customer_count) ?>customers(success)</span>
  </div>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM