-2

Possible Duplicate:
How do i “echo” a “Resource id #6” from a MySql response in PHP?

Hey guys, I got an error when I try to run my code in PHP. It displays resource id #53 in my screen. All I want is to count only the total of one of my field but I'm stuck with this error. Here's my code below:

$last_points = mysql_insert_id();
//echo $last_points , display like 12... no error
$fkid = $last_points;   // no error....
$sql = "SELECT COUNT(*) FROM downline WHERE fkmember = {$fkid}";
$execute = mysql_query($sql) or die (mysql_error());
echo $execute; //display error why?

Help me guys please. I think it's my query.

Community
  • 1
  • 1
rochellecanale
  • 83
  • 2
  • 12

4 Answers4

2

First off, resource id #53 is not an error. You are displaying a resource, not the output of the query.

To show the output, use:

$last_points = mysql_insert_id();
//echo $last_points , display like 12... no error
$fkid = $last_points;   // no error....
$sql = "SELECT COUNT(*) FROM downline WHERE fkmember = {$fkid}";
$execute = mysql_query($sql) or die (mysql_error());
print_r(mysql_fetch_array($execute)); //display error why?

Secondly, the mysql_* functions are deprecated. You should look into learning and utilising the mysqli or PDO libraries accordingly.

Daniel Li
  • 14,976
  • 6
  • 43
  • 60
0

Instead of trying to echo a resultset(as received because of mysql_query) do this:

print_r( mysql_fetch_array($execute) );
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
0

By codeigniter way

In Model:

function getCount($fkid)
        {
            $Qry = "SELECT * FROM downline WHERE fkmember = $fkid};
            $query = $this->db->query($Qry);
            return $query->num_rows();
        }

In controller:

echo $Count = $this->modelname->getCount($id);
iLaYa ツ
  • 3,941
  • 3
  • 32
  • 48
0

$execute is an array so you need to print it among echoing it

print_r($execute);
GautamD31
  • 28,552
  • 10
  • 64
  • 85