[SOLVED] Counting in an array
Posted: Tue Jun 29, 2004 3:54 pm
I am sure that this has been discussed in the forum somewhere before, but I can not find anything to help me.... so if you could, here is what I am trying to do.
Scenario: I have approximatly 100 monitor's that I am trying to track in our office. I want to list the monitor's from a database by CRT's and LCD's. I then want to place the information in a table that will list the number of 15" CRT's, 17" CRT's and 21" CRT''s. I then want to do the same with LCD. Along with this I want to give a total number of monitors.
First:
Second:
Now the problem that I am having is doing the count for each type within one large array! I have tried several different things, but nothing has worked properly, and the one above does not work either.......HELP!
Scenario: I have approximatly 100 monitor's that I am trying to track in our office. I want to list the monitor's from a database by CRT's and LCD's. I then want to place the information in a table that will list the number of 15" CRT's, 17" CRT's and 21" CRT''s. I then want to do the same with LCD. Along with this I want to give a total number of monitors.
First:
Code: Select all
<?php
$sqlmonitors = "SELECT * FROM monitor";
$result = mysql_query($sql) or die("<b>MySQL Error 1:</b> ".mysql_errno()." : ".mysql_error());
$numrows = mysql_numrows($result);
?>Code: Select all
<?php
$x=0;
while($x<$numrows){
$array = mysql_fetch_assoc($result);
while (list($indice,$crt) = each($array)){
if ($crt=="LCD"){
$num = count($crt);
echo $num;
}
}
$x++;
}?>