用计数显示查询结果

时间:2017-06-07 02:27:43

标签: php mysql

我正在使用count语句进行查询,我想显示结果 像这样的东西

something like this

我有一个名为for /R "C:\My Test\" %%f in (activity*.json) do ( set "moveme=%%f" call :select ) ... goto :eof :select set /a unique=%random% if exist "D:\Output\activity%unique%.json" goto Select copy "%moveme%" D:\Output\activity%unique%.json goto :eof 的文件,我在(显然)函数中进行查询。

这些是我的职能:

functions.php

我有另一个名为function conection($bd_config){ try { $conection = new PDO('mysql:host=localhost;dbname='.$bd_config['database'], $bd_config['user'], $bd_config['pass']); return $conection; } catch (PDOException $e) { return false; } } function checksession(){ if (!isset($_SESSION['user'])) { header('Location: ' . ROUTE. '/login.php'); } } @$us = $_SESSION['USER'][0]; function notification_count($conexion, $us){ $count = $conection->prepare('SELECT * FROM postulate WHERE du = $us AND seen = 0'); $count->execute(); $total = $count->rowCount(); $total = $count->fetchColumn(); return $total; } 的文件,其中我"呼叫" lateral.php

的功能和视图

latera.view.php

lateral.php

<?php session_start(); require 'extras/config.php'; include 'functions.php'; checksession(); $conection = conection($bd_config); $quantity = notification_count($conection, $us); require "views/lateral.php";

lateral.view.php

1 个答案:

答案 0 :(得分:0)

在我需要进行查询的函数文件中:

function notifications_count($conection, $us){
    $count= $conection->prepare("SELECT COUNT(*) FROM postul WHERE du = $us AND seen = 0");
    $count->execute();
    $number_notu = $count->fetchAll();
    return $number_notu;
}

然后在notifications.php的文件中,我只打印代码并要求查看(HTML)我需要输入这样的内容:

<?php session_start();

require 'extra/config.php';
require 'functions.php';

$conection = conection($bd_config);
if (!$conection) {
    header('Location: error.php');
}

$postul= get_people($notu_config['post_notu'], $conection, $us);

if (!$postul) {
    $vacio = "<li>The aren't any notifications</li>";
}

$total_notu = notu_count($conection, $us);

require "views/notifications.php";

并且在我仅打印HTML的通知视图中,我需要制作foreach

<div class="block-section text-center ">
  <img src="images/<?php echo($_SESSION['user'][14])  ?>" class="img-rounded" alt="">
  <div class="white-space-20"></div>
  <h4><a href="profile.php"><?php echo($_SESSION['user'][3])  ?></a></h4>
  <div class="white-space-20"></div>
  <ul class="list-unstyled">
    <li><a href="messages.php"> Messages</a></li>
    <?php foreach ($total_notu as $notu) : ?>
    <li><a href="notificaciones.php"> Notificaciones <span class="badge "><?php echo "$notu[0]"; ?></span></a></li>
  <?php endforeach; ?>
    <li><a href="change.php"> Change password</a></li>

  </ul>
  <div class="white-space-20"></div>
</div>
</div>
<div class="col-md-9 col-sm-9">
<!-- Block side right -->

我希望我可以像我一样帮助某人和他人一样:)