Sum of tables according to session id

2

What I'm doing is summing up the number of tables according to the id of the logged-in user, so I'm making no value is proven.

Bank:

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";
    ?>
    
asked by anonymous 11.11.2015 / 02:42

2 answers

1

You can do this as follows:

<?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";  
    }
?>
    
11.11.2015 / 02:47
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";  
    }


?>
    
11.11.2015 / 15:04