SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Show Pirticular Number of Units (Not Total Units)

    Hi,

    I am trying to display a number of pirticular units in a database. I have the following which shows the total number of units, but not the pirticular units.

    For example, the code below will show: There are 11 Widgets.

    What I am trying to show is:

    There are 4 Red Widgets.
    There are 2 Blue Widgets.
    There are 5 Green Widgets.

    Does anyone know how to do this please?

    Code:
    There are <?php
    
    $result = mysql_query("SELECT * FROM organiserdbase", $link);
    $num_rows = mysql_num_rows($result);
    
    echo "$num_rows \n";
    
    ?> Widgets

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Can you show us the relevant contents of one or two rows from your table?

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Row: category

    event manager
    party planner

    I am trying to read 'category' to show their are 16 Event Managers and 3 Party Planners.

    At the moment I can only 19.

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    What does this show you?

    PHP Code:
    $sql "SELECT count(category) from organiserdbase
    WHERE category = 'event manager'"


  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This also picks out the total number of values. It shows 11 Red Widgets instead of 4 Red Widgets.

  6. #6
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Does anyone have any suggestions please?

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Just how many tables do you have, and do they contain widgets or people?

    I am trying to read 'category' to show their are 16 Event Managers and 3 Party Planners.
    Then:

    This also picks out the total number of values. It shows 11 Red Widgets instead of 4 Red Widgets.
    I think its time to show us the contents of 2 or 3 rows of one of these databases.

  8. #8
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    Whats the easiest way to do that, Im just using Widgets as an example obviously.

    Code:
    $result = mysql_query("SELECT * FROM organiserdbase", $link);
    $result = "SELECT count(category) from organiserdbase
    WHERE category = 'event manager'";
    Should this work?

  9. #9
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Did you try it? What happens?
    PHP Code:
    $qry "SELECT count(category) from organiserdbase WHERE category = 'event manager'";
    $result mysql_query($qry$link);
    $a mysql_fetch_array($result);

    var_dump$a ); 

  10. #10
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Did you try it? What happens?
    PHP Code:
    $qry "SELECT count(category) from organiserdbase WHERE category = 'event manager'";
    $result mysql_query($qry$link);
    $a mysql_fetch_array($result);

    var_dump$a ); 
    Hi, I tried this but it prints the code out on the page.

    When I echo the result it echoes the following "Resource id #6" Not sure what that means.


    I tried the below but it also echoed the total overall number of units in the row. It didn't read how many "event manager" there are.

    Code:
    $sql = "SELECT count(category) from organiserdbase
    WHERE category = 'event manager'";

  11. #11
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Does anyone have any suggestions on what I can do this? There must be a way of doing it.


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
  •