Re: Re: Incrementing variables based on database data

From: Date: Tue, 12 Aug 2008 21:07:36 +0000
Subject: Re: Re: Incrementing variables based on database data
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-278006@lists.php.net to get a copy of this message
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@onshore.com> wrote in message news:48A1F7A9.6050603@onshore.com...
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@intermedia.net> wrote in message news:A0.25.04075.476F1A84@pb1.pair.com...
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@intermedia.net 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!

« previous php.general (#278006) next »