SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting summary data from a table - how?

    Hello. I'm so pleased to find this wonderful, active forum! I'm very new to php and I'm trying to learn it, but I really need a bit of help. You see, I'm trying to generate a simple "stats" page from a table in my MySQL database. I want a series of single number results, e.g., total number of records in the table, number of 2's in field such and such, number of 3's in the field..., etc. - Just statistics

    I connect to my database, then declare each variable with a SQL query for them. Then create my table and echo the resulting variable into each cell - right?

    Well, I get is a single number in each cell, but they are wrong numbers and oddly they are sequential (the first number is 8, then 9, then 10, then 11 and so on.

    This is the PHP I'm using:

    <?php

    $total = mysql_query("SELECT COUNT(appID) FROM awards GROUP BY appID;",$db);

    $brown = mysql_query("SELECT COUNT(appID) FROM awards WHERE awards.awardID=1",$db);

    $emerald = mysql_query("SELECT COUNT(appID) FROM awards WHERE awards.awardID=2 GROUP BY awards.appID",$db);

    $inprogress = mysql_query("SELECT COUNT(appID) FROM awards WHERE statusID<5 GROUP BY appID",$db);


    ?>

    <table>

    <tr align="center">
    <td align="right">July 2001</td>
    <td align="center"><?php echo $total ?></td>
    <td align="center"><?php echo $inprogress ?></td>
    <td align="center"><?php echo $brown ?></td>
    <td align="center"><?php echo $emerald ?></td>
    </tr></table>

    Any ideas?

  2. #2
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem lies in that you have just retrieved a result, not the particular information you want. You actually have to pull the info from the result before you can use it. Try using mysql_result like so:
    PHP Code:
    $total mysql_query("SELECT COUNT(appID) FROM awards GROUP BY appID;",$db);
    $total mysql_result($total,0,0); 
    This would retreive any info that is in the first row and first column of the result set. Do the same for each of the three other queries and it should work just fine.
    Kevin

  3. #3
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It worked tubedogg! Thank you so much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •