0

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

  • Please don't use `mysql` function .perfer `mysqli` or `PDO` . see the [link](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – gaurav Feb 06 '17 at 14:35
  • Ok Thanks I will edit my code –  Feb 06 '17 at 14:36
  • try to `echo $_SESSION['login_username']` see that session variable is changing or not. – gaurav Feb 06 '17 at 14:41
  • yes when i change account that also change. –  Feb 06 '17 at 14:42
  • There's more code there and actually when i echo that it leads me to an error: syntax error, unexpected '$_SESSION' (T_VARIABLE) –  Feb 06 '17 at 14:59
  • Even without info in the database the value are 1 1 and 2 –  Feb 06 '17 at 15:37
  • we can try without `count()` because in notification you want to know total no. of row to show as badge so try `SELECT * from pedidos where p_nomeuti='{$_SESSION['login_username']}' and p_estado='0'` & `SELECT * from pedidos where p_autor='{$_SESSION['login_username']}'` – gaurav Feb 07 '17 at 10:15
  • Still not working , when i echo those variables they have allways the same value even without info on database –  Feb 07 '17 at 10:29
  • are you starting session `session_start()` in first php file. – gaurav Feb 07 '17 at 10:31
  • ye i have a file called session.php that has the code to start the session and i call it in all of my files –  Feb 07 '17 at 10:34
  • can you share more code – gaurav Feb 07 '17 at 10:39
  • Sure ill post all my menu code –  Feb 07 '17 at 10:39
  • specailly php code – gaurav Feb 07 '17 at 10:40
  • There you go , you have my sessin.php file code and the profile.php that is the main page –  Feb 07 '17 at 10:41
  • Can you send me a chat message that way this post doesn't get bigger and bigger and at the end you just post the answer ? –  Feb 07 '17 at 10:42
  • Randomly this started working with your sql command thanks but can you help me with another thing ? –  Feb 07 '17 at 10:52
  • 1
    what values you are storing in `$_SESSION['login_username']` because in second file you are doing `$check = $_SESSION['login_username']` on that – gaurav Feb 07 '17 at 10:53
  • notification working? – gaurav Feb 07 '17 at 10:55
  • The notification It's already working randomly started working can you help me another thing I'm checking if the user is the owner of a post and if he isn't it doesn't let him delete the post. I will post that code as well. –  Feb 07 '17 at 10:56
  • it will be better for you to ask new question instead of edit this . – gaurav Feb 07 '17 at 10:59
  • Ok how can i close this "ticket" and tell that you helped me ? –  Feb 07 '17 at 11:00
  • choose as right answer – gaurav Feb 07 '17 at 11:12

1 Answers1

0

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.

gaurav
  • 1,281
  • 1
  • 13
  • 25