-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
  • 69
  • 2
  • 10

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,448
  • 6
  • 41
  • 59
0

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

print_r( mysql_fetch_array($execute) );
hjpotter92
  • 75,209
  • 33
  • 136
  • 171
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,887
  • 3
  • 27
  • 45
0

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

print_r($execute);
Gautam3164
  • 28,027
  • 10
  • 58
  • 83