进度条php和mysql

时间:2015-01-12 19:00:59

标签: php mysql pdo

我需要在显示每个人为他工作的客户数量的人名旁边建立进度条。当您看到代码时,您将了解我的问题。我不知道如何构建它。

在正文结束之前,在脚本标记之前我有进度条和var显示来自db的名称。我需要显示名称和旁边的进度条与客户的百分比。

这是我的表格 enter image description here enter image description here

<?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>';

?>

0 个答案:

没有答案