Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

php mysql query to db displays only resource id 228?

I have a query:
'SELECT `project`, COUNT(*) FROM `table-name` GROUP BY `project`

the only thing it returns is "Resource id #228"

I have no idea what this means or why the query returns this message, any help would be appreciated.
0
digitalkandy
Asked:
digitalkandy
  • 3
  • 2
1 Solution
 
hieloCommented:
$res = mysql_query("SELECT `project`, COUNT(*) as ct FROM `table-name` GROUP BY `project`") or die( mysql_error() );
while( $row = mysql_fetch_assoc($res) )
{
 echo $row['project'] . " " . $row['ct'];
}
0
 
digitalkandyAuthor Commented:
you are a rock star!

just curious as to what the "Resource id' means, if you care to explain I would appreciate it, if not I understand.

Thanks for taking the time.
0
 
hieloCommented:
when you execute this:
$res = mysql_query(...);

$res does NOT contain the result of the query. It contains "something" that "points to/holds"  the real data. That "something" is referred to as "resource" in php. So if you do:
echo $res;

you are NOT getting the real data. You are getting the resource that points to the place where your real data is stored. Instead you need to "extract" the data from the resource. That's what this does:
$row = mysql_fetch_assoc($res )

it "extracts" the data from the resource and puts in in $row. So $row contains the actual data.
0
 
digitalkandyAuthor Commented:
nice, thank you for the explanation, it always helps to know the why and not just the how.
0
 
hieloCommented:
>>it always helps to know the why and not just the how
agree.

Glad to help. Take care.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now