Re: Re: Incrementing variables based on database data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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" <micah@xxxxxxxxxxx> wrote in message news:48A1F7A9.6050603@xxxxxxxxxxxxxx
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"" <vgullotta@xxxxxxxxxxxxxx> wrote in message
news:A0.25.04075.476F1A84@xxxxxxxxxxxxxxx
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>";
?>




--

Vinny Gullotta
Intermedia System Administrator
E vgullotta@xxxxxxxxxxxxxx
T (650) 641-4034
F (650) 424-9936
According to Einstein's Theory of Relativity, Chuck Norris can actually roundhouse kick you in the face yesterday!


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux