Gonçalo Gonçalo - 1 year ago 64
PHP Question

Notifications on menu bar with sessions

I want to show notifications like facebook has but way more simple just to inform but I'm having some problems.
This is the bug in all users they have all the same notifications even if i create a new account.
Bug
Code:

<?php
include("session.php");
?>
<html>
<head>
<link rel="icon" href="../imagens/4.png" />
<title>BlendUp</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/costum.css">
<link rel="icon" href="Icone.png" width="50px" height="45px">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div id="navbar" class="navbar navbar-fixed-top">
<div class="navbar-def">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="../login/profile.php" class="navbar-brand"> <img src="../imagens/5.png" width="125px" height="35px" ></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Pedidos
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="../forms/p_criar.php">Criar</a></li>
<li><a href="../php/p_view.php">Visualizar</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Conte├║do
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Criar</a></li>
<li><a href="#">Visualizar</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Portais
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="../forms/po_criar.php">Criar</a></li>
<li><a href="../php/po_view.php">Visualizar</a></li>
</ul>
</li>
</ul>
<?php
$result = mysqli_query($link,"SELECT * from pedidos where p_nomeuti='{$_SESSION['login_username']}' and p_estado='0'");
$result1 = mysqli_query($link,"SELECT count(*) from pedidos where p_autor='$login_session'");
$num_rows = mysqli_num_rows($result);
$num_rows1 = mysqli_num_rows($result1);
$numrowstotal= $num_rows + $num_rows1;
echo $num_rows;
echo $num_rows1;
echo $numrowstotal;
?>
<ul class="nav navbar-nav navbar-right">
<li><a class="dropdown-toggle" data-toggle="dropdown">Bem Vindo, <?php echo $login_session;?><?php echo $numrowstotal;?> </a>
<ul class="dropdown-menu">
<li><a>Por terminar <?php echo $num_rows;?></a></li>
<li><a>A fazer <?php echo $num_rows1;?></a></li>
</ul>
<li> <a href="logout.php"> Logout <img src="../imagens/6.png" style="width:15px; height:15px" align="middle" > </a> </li>
</ul>
</div>
</div><!--/.nav-collapse -->
<body style="background-color:#122a82">
</div>
<div class="container">
</head>
</html>
<link rel="stylesheet" type="text/css" href="../css/pesquisa.css">
<div class="well-searchbox">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-md-4 control-label">Keyword</label>
<div class="col-md-8">
<input type="text" class="form-control" placeholder="Keyword">
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Portais</label>
<div class="col-md-8">
<select class="form-control" placeholder="Country">
<option value="">All</option>
<option value="">Country 1</option>
<option value="">Country 2</option>
</select>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Data Inicio</label>
<div class="col-md-8">
<input class="form-control" type="date" name="dataini">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Data Fim</label>
<div class="col-md-8">
<input class="form-control" type="date" name="datafim">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-5">
<button type="submit" class="btn btn-primary">Pesquisa</button>
</div>
</form>
</div>
</body>
</html>


Session.php

<?php
include('../config/db.php');
session_start();
$check=$_SESSION['login_username'];
$session=mysqli_query($link,"select u_nick from utilizadores where u_nick='$check' ");
$row=mysqli_fetch_array($session);
$login_session=$row['u_nick'];
if(!isset($login_session))
{
header("Location:../index.html");
}
?>


I'm with php like I've said in the others questions.
This is not full code this is a part of my menu.
If you need more of my code tell me please ill post it here

Answer Source

you are using count function in query which return count of the number of rows retrieved by a SELECT statement so mysqli_num_rows() return always one .

SELECT * from pedidos where p_nomeuti='{$_SESSION['login_username']}' and p_estado='0'   
SELECT * from pedidos where p_autor='{$_SESSION['login_username']}'  

so now use mysqli_num_rows.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download