php mysql query to db displays only resource id 228?

Posted on 2008-11-07
Last Modified: 2013-12-13
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.
Question by:digitalkandy
    LVL 82

    Accepted Solution

    $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'];
    LVL 1

    Author Closing Comment

    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.
    LVL 82

    Expert Comment

    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.
    LVL 1

    Author Comment

    nice, thank you for the explanation, it always helps to know the why and not just the how.
    LVL 82

    Expert Comment

    >>it always helps to know the why and not just the how

    Glad to help. Take care.

    Featured Post

    Easy Project Management (No User Manual Required)

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now