Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-18 Thread Vinny Gullotta
Thanks all, I appreciate the follow ups and the help with the code. I'm 
still relatively new with this stuff, and never had any formal training, 
it's all just been learn as I go, and I have to learn fast as this project 
is relatively urgent to get completed. I plan on going through all of my 
code on all of these pages and cleaning it up at the end to make it more 
efficient, so I will use these tips to help do that.


Thanks again to all who helped troubleshoot this. It is working great now 
and I think my bosses will be happy. =D



Nathan Rixham [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

learn something new every day! cheers Micah :)

Micah Gersten wrote:

While it's true that '.' concatenates and ',' is a list separator, The
comma is actually more appropriate in this instance since you are just
outputting each piece.  It saves the overhead of concatenation before
output.

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



Nathan Rixham wrote:

6:  vs '
when you use  php will parse the enclosed string for variables, when
you use ' it won't; so ' leads for faster code, and also encourages
you to code strongly by closing strings and concatenating variables.
Further it allows you to use valid html  around attributes rather
than the invalid '

7: , vs .
there is no vs :) to concatenate we use . (period) not , (comma)

so for 6  7..
echo 'td' . $i['servername'] . '/td';

I'm going to stop there, hope it helps a little bit; and I won't go
any further as half the fun is learning; so you finding out how to
save time on queries and write your own db handlers etc is not my
domain I reckons

Regards

nathan




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



[PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta
What I want to do is find the top 10 servers where the column steps = 
iisreset. The following code works great except that the page is not 
displaying the servername in the 'Server Name' column of my results (nothing 
appears, the column is just blank).


servername and steps are the important columns in the database table. 
$_POST[time1] and $_POST[time2] come from a form submitted.


When I copy and paste the entire select statement into the SQL tab in 
phpmyadmin (and replace the time variables with actual times corresponding 
to the timestamp column), it displays the correct results including 
servername. Everything works in the php page's results except for the 
servername. I feel like it's right in front of my face and that's why I 
can't see it lol. Any help would be greatly appreciated. Thanks in advance 
=)


My code...

$query = SELECT servername, COUNT(steps) FROM monitoring WHERE steps LIKE 
'iisreset' AND timestamp = '$_POST[time2]' AND timestamp = '$_POST[time1]' 
GROUP BY servername ORDER BY COUNT(*) DESC LIMIT 10;

$result = mysql_query($query) or die(mysql_error());

# display column titles
echo centertable class='table'tr;
echo td class='tableHeader'centersmallbCount/b/small/td;
echo td class='tableHeader'centersmallbServer 
Name/b/small/td;

echo /tr;

#display results
while($i = mysql_fetch_row($result))
{
echo trtdsmallcenter, $i[COUNT('steps')], 
/center/small/td;

echo tdsmallcenter, $i[servername] ,/center/small/td/tr;
}
echo /table/centerbr; 



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



Re: [PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta
Dan Joseph [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
On Wed, Sep 17, 2008 at 2:17 PM, Vinny Gullotta 
[EMAIL PROTECTED]wrote:



What I want to do is find the top 10 servers where the column steps =
iisreset. The following code works great except that the page is not
displaying the servername in the 'Server Name' column of my results 
(nothing

appears, the column is just blank).

servername and steps are the important columns in the database table.
$_POST[time1] and $_POST[time2] come from a form submitted.

When I copy and paste the entire select statement into the SQL tab in
phpmyadmin (and replace the time variables with actual times 
corresponding

to the timestamp column), it displays the correct results including
servername. Everything works in the php page's results except for the
servername. I feel like it's right in front of my face and that's why I
can't see it lol. Any help would be greatly appreciated. Thanks in 
advance

=)

My code...

$query = SELECT servername, COUNT(steps) FROM monitoring WHERE steps 
LIKE
'iisreset' AND timestamp = '$_POST[time2]' AND timestamp = 
'$_POST[time1]'

GROUP BY servername ORDER BY COUNT(*) DESC LIMIT 10;
$result = mysql_query($query) or die(mysql_error());

# display column titles
echo centertable class='table'tr;
echo td class='tableHeader'centersmallbCount/b/small/td;
echo td class='tableHeader'centersmallbServer
Name/b/small/td;
echo /tr;

#display results
while($i = mysql_fetch_row($result))
{
echo trtdsmallcenter, $i[COUNT('steps')],
/center/small/td;
echo tdsmallcenter, $i[servername] 
,/center/small/td/tr;

}
echo /table/centerbr;

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



Change that COUNT(steps) to COUNT(steps) AS CountSteps, that might be
the issue.  Then you're using $i['CountSteps'].  That seems a bit more
normal looking to me atleast.

Also, try echoing out your query on the screen to see that its formating
properly in the PHP code.  You may have something wrong in there, although 
I

don't see any off hand.

--
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.




Adding as CountSteps $i['CountSteps'] still leaves the column blank.

echo $result; gives me an output of:
Resource id #3

and

echo $query;

just gives me an error.

One thing I don't understand is why echo $result; gives me Resource id #3 as 
an output. What does that mean? 



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



Re: [PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta
Dan Joseph [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
On Wed, Sep 17, 2008 at 2:30 PM, Vinny Gullotta 
[EMAIL PROTECTED]wrote:



Dan Joseph [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 On Wed, Sep 17, 2008 at 2:17 PM, Vinny Gullotta 
[EMAIL PROTECTED]

wrote:

 What I want to do is find the top 10 servers where the column steps =

iisreset. The following code works great except that the page is not
displaying the servername in the 'Server Name' column of my results
(nothing
appears, the column is just blank).

servername and steps are the important columns in the database table.
$_POST[time1] and $_POST[time2] come from a form submitted.

When I copy and paste the entire select statement into the SQL tab in
phpmyadmin (and replace the time variables with actual times
corresponding
to the timestamp column), it displays the correct results including
servername. Everything works in the php page's results except for the
servername. I feel like it's right in front of my face and that's why I
can't see it lol. Any help would be greatly appreciated. Thanks in
advance
=)

My code...

$query = SELECT servername, COUNT(steps) FROM monitoring WHERE steps
LIKE
'iisreset' AND timestamp = '$_POST[time2]' AND timestamp =
'$_POST[time1]'
GROUP BY servername ORDER BY COUNT(*) DESC LIMIT 10;
$result = mysql_query($query) or die(mysql_error());

# display column titles
echo centertable class='table'tr;
echo td 
class='tableHeader'centersmallbCount/b/small/td;

echo td class='tableHeader'centersmallbServer
Name/b/small/td;
echo /tr;

#display results
while($i = mysql_fetch_row($result))
{
echo trtdsmallcenter, $i[COUNT('steps')],
/center/small/td;
echo tdsmallcenter, $i[servername]
,/center/small/td/tr;
}
echo /table/centerbr;

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


 Change that COUNT(steps) to COUNT(steps) AS CountSteps, that might

be
the issue.  Then you're using $i['CountSteps'].  That seems a bit more
normal looking to me atleast.

Also, try echoing out your query on the screen to see that its formating
properly in the PHP code.  You may have something wrong in there, 
although

I
don't see any off hand.

--
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.




Adding as CountSteps $i['CountSteps'] still leaves the column blank.

echo $result; gives me an output of:
Resource id #3

and

echo $query;

just gives me an error.

One thing I don't understand is why echo $result; gives me Resource id #3
as an output. What does that mean?

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



That's basically your result set ID number inside PHP.

as for $query, what error are you getting?  Does this $query echo out:

$query = SELECT servername, COUNT(steps) AS CountSteps FROM monitoring
WHERE steps LIKE 'iisreset' AND timestamp = ' . $_POST['time2'] . ' AND
timestamp = ' . $_POST['time1'] . ' GROUP BY servername ORDER BY 
COUNT(*)

DESC LIMIT 10;

--
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.



It's actually not an error, it's the select statement that is echo'd

echo $query;

yields

SELECT servername, COUNT(steps) as CountSteps FROM monitoring WHERE steps = 
'IISRESET' AND timestamp = '2008-09-17 11:40:34' AND timestamp = 
'2008-08-17' GROUP BY servername ORDER BY COUNT(*) DESC LIMIT 10 



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



Re: [PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta

Still no luck displaying the stupid servername. Any other things I can try?


Micah Gersten [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
You'll want to change your Order By statement to 'ORDER BY CountSteps 
DESC'.


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



Vinny Gullotta wrote:

echo $query;

yields

SELECT servername, COUNT(steps) as CountSteps FROM monitoring WHERE
steps = 'IISRESET' AND timestamp = '2008-09-17 11:40:34' AND
timestamp = '2008-08-17' GROUP BY servername ORDER BY COUNT(*) DESC
LIMIT 10




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



Re: [PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta
Dan Joseph [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
On Wed, Sep 17, 2008 at 2:17 PM, Vinny Gullotta 
[EMAIL PROTECTED]wrote:



What I want to do is find the top 10 servers where the column steps =
iisreset. The following code works great except that the page is not
displaying the servername in the 'Server Name' column of my results 
(nothing

appears, the column is just blank).

servername and steps are the important columns in the database table.
$_POST[time1] and $_POST[time2] come from a form submitted.

When I copy and paste the entire select statement into the SQL tab in
phpmyadmin (and replace the time variables with actual times 
corresponding

to the timestamp column), it displays the correct results including
servername. Everything works in the php page's results except for the
servername. I feel like it's right in front of my face and that's why I
can't see it lol. Any help would be greatly appreciated. Thanks in 
advance

=)

My code...

$query = SELECT servername, COUNT(steps) FROM monitoring WHERE steps 
LIKE
'iisreset' AND timestamp = '$_POST[time2]' AND timestamp = 
'$_POST[time1]'

GROUP BY servername ORDER BY COUNT(*) DESC LIMIT 10;
$result = mysql_query($query) or die(mysql_error());

# display column titles
echo centertable class='table'tr;
echo td class='tableHeader'centersmallbCount/b/small/td;
echo td class='tableHeader'centersmallbServer
Name/b/small/td;
echo /tr;

#display results
while($i = mysql_fetch_row($result))
{
echo trtdsmallcenter, $i[COUNT('steps')],
/center/small/td;
echo tdsmallcenter, $i[servername] 
,/center/small/td/tr;

}
echo /table/centerbr;

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



$i[servername]

Try:  $i['servername']

notice the ' and ' around the name.  I've heard you can do w/o those, but
I've had issues in the past where it didn't work.  ITs also good practice 
to

use 'em.

--
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.




yeah, I've tried that combination before, but just for grins I tried it 
again, and same result. It displays the counts but not the servernames. 



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



Re: [PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta
var_dump($i); looks messy, but I can see the server names in there and they 
are the correct names.



Micah Gersten [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

Do var_dump($i) in the loop to see if you're getting the data you want.

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



Vinny Gullotta wrote:

Still no luck displaying the stupid servername. Any other things I can
try?


Micah Gersten [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

You'll want to change your Order By statement to 'ORDER BY CountSteps
DESC'.

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



Vinny Gullotta wrote:

echo $query;

yields

SELECT servername, COUNT(steps) as CountSteps FROM monitoring WHERE
steps = 'IISRESET' AND timestamp = '2008-09-17 11:40:34' AND
timestamp = '2008-08-17' GROUP BY servername ORDER BY COUNT(*) DESC
LIMIT 10







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



Re: [PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta

var_dump looks like this:

array(2) { [0]= string(9) wehost006 [1]= string(2) 72 } array(2) { 
[0]= string(8) H7848-49 [1]= string(2) 71 } array(2) { [0]= string(7) 
H7853-2 [1]= string(2) 70 } array(2) { [0]= string(7) H7842-2 [1]= 
string(2) 64 } array(2) { [0]= string(9) WEHOST005 [1]= string(2) 
64 } array(2) { [0]= string(7) h7835-2 [1]= string(2) 57 } array(2) 
{ [0]= string(9) wehost007 [1]= string(2) 56 } array(2) { [0]= 
string(7) H7814-1 [1]= string(2) 55 } array(2) { [0]= string(5) 
H0542 [1]= string(2) 54 } array(2) { [0]= string(8) H7811-12 [1]= 
string(2) 54 }



Dan Joseph [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
On Wed, Sep 17, 2008 at 4:21 PM, Vinny Gullotta 
[EMAIL PROTECTED]wrote:


var_dump($i); looks messy, but I can see the server names in there and 
they

are the correct names.


Micah Gersten [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 Do var_dump($i) in the loop to see if you're getting the data you want.


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



Vinny Gullotta wrote:


Still no luck displaying the stupid servername. Any other things I can
try?


Micah Gersten [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]


You'll want to change your Order By statement to 'ORDER BY CountSteps
DESC'.

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



Vinny Gullotta wrote:


echo $query;

yields

SELECT servername, COUNT(steps) as CountSteps FROM monitoring WHERE
steps = 'IISRESET' AND timestamp = '2008-09-17 11:40:34' AND
timestamp = '2008-08-17' GROUP BY servername ORDER BY COUNT(*) DESC
LIMIT 10







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



Can you show us one of the var_dumps?

--
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.




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



Re: [PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta

If by key you mean the column in the database, it's called: servername

Micah Gersten [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

What is the key for the server name?  That's what you need when you
output it.

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



Vinny Gullotta wrote:

var_dump($i); looks messy, but I can see the server names in there and
they are the correct names.


Micah Gersten [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Do var_dump($i) in the loop to see if you're getting the data you want.

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



Vinny Gullotta wrote:

Still no luck displaying the stupid servername. Any other things I can
try?


Micah Gersten [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

You'll want to change your Order By statement to 'ORDER BY CountSteps
DESC'.

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



Vinny Gullotta wrote:

echo $query;

yields

SELECT servername, COUNT(steps) as CountSteps FROM monitoring WHERE
steps = 'IISRESET' AND timestamp = '2008-09-17 11:40:34' AND
timestamp = '2008-08-17' GROUP BY servername ORDER BY COUNT(*) DESC
LIMIT 10










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



Re: [PHP] PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Vinny Gullotta

That was it!!! Thank you all so much for your help!!! =D


Dan Joseph [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
On Wed, Sep 17, 2008 at 4:30 PM, Vinny Gullotta 
[EMAIL PROTECTED]wrote:



If by key you mean the column in the database, it's called: servername

Micah Gersten [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 What is the key for the server name?  That's what you need when you

output it.

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



Vinny Gullotta wrote:


var_dump($i); looks messy, but I can see the server names in there and
they are the correct names.


Micah Gersten [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Do var_dump($i) in the loop to see if you're getting the data you 
want.


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



Vinny Gullotta wrote:

Still no luck displaying the stupid servername. Any other things I 
can

try?


Micah Gersten [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

You'll want to change your Order By statement to 'ORDER BY 
CountSteps

DESC'.

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



Vinny Gullotta wrote:


echo $query;

yields

SELECT servername, COUNT(steps) as CountSteps FROM monitoring WHERE
steps = 'IISRESET' AND timestamp = '2008-09-17 11:40:34' AND
timestamp = '2008-08-17' GROUP BY servername ORDER BY COUNT(*) 
DESC

LIMIT 10










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



Thanks, I know your problem, sorry for not seeing this sooner.
mysql_fetch_row returns the numerical array types.  $array[0]...  You want
to use mysql_fetch_array().  Change to that, and you should be seeing the
servername's.

--
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.




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



[PHP] Incrementing variables based on database data

2008-08-12 Thread Vinny Gullotta
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



[PHP] Re: Incrementing variables based on database data

2008-08-12 Thread Vinny Gullotta
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;
?




--

Vinny Gullotta
Intermedia System Administrator
E [EMAIL PROTECTED]
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



Re: [PHP] Re: Incrementing variables based on database data

2008-08-12 Thread Vinny Gullotta
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;
?






--

Vinny Gullotta
Intermedia System Administrator
E [EMAIL PROTECTED]
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



Re: [PHP] PHP querying mysql db for data limited to the last month

2008-08-05 Thread Vinny Gullotta
Sorry, I took that stuff out because it was making the page not load and so 
I figured it was wrong. I guess I should have posted the whole thing, but 
since it didn't work I left it out.


Micah, thank you very much for the idea, it is working great!!!


Micah Gersten [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

1.  To get last months date, you can use strtotime(1 month ago)
instead of mktime.
2.  I don't see anywhere in the code where you are limiting by date.
Try using  and .  Between is tricky on dates.

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



Vinny Gullotta wrote:

So I have this code I'm working with (pasted below) that queries a
mysql db table called timetracking. The goal of the page is to search
the db for all data based on a certain engineer, sorted by product and
it takes pre-defined values based on actions performed, sums them
based on product and display's the percentage of time an engineer has
spent on each product. Everything works great except I need to limit
the results to the last months data only, but everything I try seems
to just break it. Can anyone push me in the right direction a little?
I have tried using BETWEEN in the SELECT statement, some while
statements and if statements, and all I do is keep breaking it. If
anyone has any ideas, it would be exceptionally helpful.

Thanks in advance,
Vinny


?php
$total = 0;
$today = date('Y-m-d h:i:s');
$monthago = date(Y-m-d h:i:s, mktime(date(h), date(i),
date(s), date(m)-1, date(d),   date(Y)));
echo Today = , $today;
echo brOne Month Ago = , $monthago, br;

$query = SELECT *, SUM(timespent) FROM timetracking WHERE engineer =
'$engineer' GROUP BY product;
$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query) or die(mysql_error());
echo center;

 while($row = mysql_fetch_array($result)){
  $total = $row['SUM(timespent)'] + $total;
 }
 while($row = mysql_fetch_array($result2)){
  $perc = $row['SUM(timespent)'] * 100 / $total;
  echo [ font color=#1E429B size=+1, $row[product].  = .
number_format($perc,2), %/font ];
 }

?





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



[PHP] PHP querying mysql db for data limited to the last month

2008-08-04 Thread Vinny Gullotta
So I have this code I'm working with (pasted below) that queries a mysql db 
table called timetracking. The goal of the page is to search the db for all 
data based on a certain engineer, sorted by product and it takes pre-defined 
values based on actions performed, sums them based on product and display's 
the percentage of time an engineer has spent on each product. Everything 
works great except I need to limit the results to the last months data only, 
but everything I try seems to just break it. Can anyone push me in the right 
direction a little? I have tried using BETWEEN in the SELECT statement, some 
while statements and if statements, and all I do is keep breaking it. If 
anyone has any ideas, it would be exceptionally helpful.


Thanks in advance,
Vinny


?php
$total = 0;
$today = date('Y-m-d h:i:s');
$monthago = date(Y-m-d h:i:s, mktime(date(h), date(i), date(s), 
date(m)-1, date(d),   date(Y)));

echo Today = , $today;
echo brOne Month Ago = , $monthago, br;

$query = SELECT *, SUM(timespent) FROM timetracking WHERE engineer = 
'$engineer' GROUP BY product;

$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query) or die(mysql_error());
echo center;

 while($row = mysql_fetch_array($result)){
  $total = $row['SUM(timespent)'] + $total;
 }
 while($row = mysql_fetch_array($result2)){
  $perc = $row['SUM(timespent)'] * 100 / $total;
  echo [ font color=#1E429B size=+1, $row[product].  = . 
number_format($perc,2), %/font ];

 }

?


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