Well, MySQL can aggregate the data for you so you don't have to pass it
to PHP.  It can just give you the results.  I suggest reading up on the
SELECT COUNT syntax and the GROUP BY syntax in MySQL.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Vinny Gullotta wrote:
> Well, what I need to be able to do is then take the numbers of each
> count and figure out which is used the most. We use this database to
> log actions taken on servers in our network. What my boss wants me to
> come up with is a list of which commands are issued the most, which
> servers get the most attention, and for each server, which command is
> issued the most, and so I was going to kind of do it messy-like as I'm
> not really 100% sure of the best way to do it, but my goal was to
> create the count variables and then compare them using if statements
> to see which one is used the most. If you have a way of doing this
> more efficiently, I'd love to hear it. I'm not the best programmer in
> the world and I'm kind of just getting back into this stuff, so I'm
> all ears for any suggestions you may have =)
>
>
>
>
> "Micah Gersten" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Why not let the DB do this for you?  You can group by whatever column
>> that is and select count(*), column_your_looking_for.
>>
>> Thank you,
>> Micah Gersten
>> onShore Networks
>> Internal Developer
>> http://www.onshore.com
>>
>>
>>
>> Vinny Gullotta wrote:
>>> Nevermind, I figured it out. I needed to make the if statements use ==
>>> instead of = like this:
>>>
>>> if ($i[4] == "IISRESET") {
>>> $iiscount = $iiscount + 1;
>>> }
>>>
>>> etc. =)
>>>
>>>
>>> ""Vinny Gullotta"" <[EMAIL PROTECTED]> wrote in message
>>> news:[EMAIL PROTECTED]
>>>> below is the output I'm seeing along with my code. There are 11425
>>>> items in the database, many of each of these possible values for
>>>> $i[4], however you'll see from my Output that the $iiscount variable
>>>> is the only one being incremented and it is getting incremented for
>>>> every row in the table. Can anyone see anything I'm doing
>>>> incorrectly? The data in this column in the table is formatted as
>>>> TEXT. Thanks in advance for any help you can provide. =)
>>>>
>>>> 11425
>>>> 0
>>>> 0
>>>> 0
>>>> 0
>>>> 0
>>>> 0
>>>> 0
>>>>
>>>> ____________________________________________
>>>> $query = "SELECT * FROM table";
>>>> $result = mysql_query($query) or die(mysql_error());
>>>> $iiscount = 0;
>>>> $cfcount = 0;
>>>> $nlbcount = 0;
>>>> $srcount = 0;
>>>> $sacount = 0;
>>>> $rebootcount = 0;
>>>> $apccount = 0;
>>>> $othercount = 0;
>>>>
>>>> while($i = mysql_fetch_row($result)) {
>>>> if ($i[4] = "IISRESET") {
>>>>  $iiscount = $iiscount + 1;
>>>> } elseif ($i[4] = "CF Restart") {
>>>>  $cfcount = $cfcount + 1;
>>>> } elseif ($i[4] = "NLB STOP IISRESET") {
>>>>  $nlbcount = $nlbcount +1;
>>>> } elseif ($i[4] = "Service Restart") {
>>>>  $srcount = $srcount + 1;
>>>> } elseif ($i[4] = "Restart System Attendant") {
>>>>  $sacount = $sacount + 1;
>>>> } elseif ($i[4] = "Reboot") {
>>>>  $rebootcount = $rebootcount + 1;
>>>> } elseif ($i[4] = "APC Reboot") {
>>>>  $apccount = $apccount + 1;
>>>> } elseif ($i[4] = "Other") {
>>>>  $othercount = $othercount + 1;
>>>> }
>>>> }
>>>> echo $iiscount, "<br>";
>>>> echo $cfcount, "<br>";
>>>> echo $nlbcount, "<br>";
>>>> echo $srcount, "<br>";
>>>> echo $sacount, "<br>";
>>>> echo $rebootcount, "<br>";
>>>> echo $apccount, "<br>";
>>>> echo $othercount, "<br>";
>>>> ?>
>>>>
>>>>
>>>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to