using php with mysql. I have table_one and column_something that is enum type with the values "A", "B" and "C". I would like to count these values and then echo how many there are of each of these individual values from column_something. I'm confused about this. This is how I am going about it but can't finish or am I totally wrong? Thanks in advance for any help.

OwenTheSamoan

$array = array(
"A" => 1,
"B" => 1,
"C" => 1);

$query = ("select column_something from table_one where something ='$something'");

    SELECT count(*) as count FROM `table_one` GROUP BY column_something

    ~Brett

      I'm confused as to how I would echo the individual count for each value

        <?php
        
        while($row = mysql_fetch_array($result))
        {
            echo $row['count'];
        }
        
        ?>

        ~Brett

          I'm feeling very stupid here. I am getting error meesages. this is what I have mysql_fetch_array(): supplied argument is not a valid MySQL

          $result = ("SELECT count(column_something) as count FROM table where something ='$something' group by column_something");
          while($row = mysql_fetch_array($result))
          {
          echo $row['count'];
          }

            umm... no...

            <?php
            $query = "SELECT *, count(*) as count FROM `table` GROUP BY column_something";
            $result = mysql_query($query);
            while($row = mysql_fetch_array($result))
            {
                echo $row['count'].'<br>';
            }
            ?>

            ~Brett

              Ahhhhh, that worked perfectly. Thank you very, very much! One last question. I now have three seperate numerical count results. Is it possible to add these sperate results to variables? An example would be... $A = 25; $B = 30; $C =17; Thank you once again for the help.

                <?php
                $query = "SELECT *, count(*) as count FROM `table` GROUP BY column_something";
                $result = mysql_query($query);
                while($row = mysql_fetch_array($result))
                {
                    $$row['column_something'] = $row['count'];
                }
                
                echo $A.' '.$B.' '.$C.' '.$D;
                ?> 

                ~Brett

                  Sorry to be a bother, but I have a new error. The values I am using are not actually A, B and C as used in the example. I apologize. They are actually 0, 1 and 2. Your example caused a parsing error so I put double quotes around like this echo "$0.' '.$1.' '.$2"; But instead of getting the count for each value I got this instead $0.' '.$1.' '.$2 thank you once again fro your great help.

                    what was the exact parse error?

                    ~Brett

                      Parse error: parse error, unexpected T_DNUMBER, expecting T_VARIABLE or '$'

                        while($row = mysql_fetch_array($result)){
                            $vals[$row['column_something']] = $row['count'];
                        }
                        
                        foreach($vals as $var => $val)
                        {
                            echo $var.' => '.$val.'<br>';
                        } 

                        ~Brett

                          That worked perfectly. Thank you so much for your help! It is greatly appreciated!!

                            But wouldn't it be easier to put those counts into an array instead of separate variables?

                            $counts[$row['column_something']] = $row['count']; 
                            echo $counts['A'].' '.$counts['B'].' '.$counts['C'].' '.$counts['D']; 
                            //or
                            echo join(' ', $counts);
                            

                              I'm trying the last way as an array now and I get this error message parse error, unexpected T_ECHO

                                Nevermind, I got it to work your way too. Thanks Weedpacket!!

                                  Write a Reply...