Sum of tables according to session id

Asked

Viewed 43 times

2

What I am doing is the sum of the number of tables according to the id of the user who is logged in, the way I am doing no value is demonstrated.

Bench:

id      id_affiliate      user_ip          date
 1                2       162.70.25.00     2015-11-06 08:49:47
 2                1       162.70.25.00     2015-11-06 09:49:47
 3                2       162.70.25.00     2015-11-06 10:49:47     
 4                2       162.70.25.00     2015-11-06 11:49:47
 2                1       162.70.25.00     2015-11-06 00:49:47

Code:

 <?

    $connect = mysql_connect('localhost', 'root', 'pass');

          if (!$connect) {
      die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("database", $connect);

    $consulta = mysql_query("SELECT id_affiliate FROM easy_affiliate_stats WHERE id_affiliate = . "$_SESSION["id_affiliate"], $connect);
    //Conta quantos registros possuem na tabela
    $total= mysql_num_rows($consulta);
    //Mostra o valor
    echo "Atualmente há $total registros";
    ?>
  • id_affiliate is returning right? within SESSION

  • The page is coming blank, shows no error within localhost.

  • I posted an answer for you.

  • When submitting the request, the page returns blank, no error and no information on the page. :/

  • Error is in query concatenation

  • Ok. I am using the code you sent me, the page is opening normally, but returns me the value of 0 records.

  • If you are returning zero, you are not passing $_SESSION correctly, echo $_SESSION["id_affiliate"] to see what returns.

  • I did the informed and returned no value.

  • Then the problem is in your Sesssion that is not working. Are you starting Session at the beginning of the file? session_start();

  • It was not, I added and still continues to return 0, it will be because the entries are saved in another table?

  • Managed to make?

Show 6 more comments

2 answers

1


You can do it this way:

<?php
    mysql_connect('localhost', 'root', 'pass') or print mysql_error();
    mysql_select_db("database");

    $consulta = mysql_query("SELECT id_affiliate FROM easy_affiliate_stats WHERE id_affiliate = '$_SESSION[id_affiliate]'");
    if(mysql_num_rows($consulta) >= 0){
        echo "Atualmente há ".mysql_num_rows($consulta)." registros";
    } else {
        echo "Nenhum registro foi encontrado";  
    }
?>

0

<?php
error_reporting('0');
   mysql_connect('localhost', 'root', 'pass') or die ('erro-01');
   mysql_select_db("database") or die ('erro-02');

$total= mysql_num_rows( mysql_query("SELECT id_affiliate FROM easy_affiliate_stats WHERE id_affiliate ='$_SESSION[id_affiliate]'"));


  if($total >= 0){
        echo "Atualmente há ".$total." registros";
    } else {
        echo "Nenhum registro foi encontrado";  
    }


?>
  • simple... this way is to work I hope to have helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.