problems reassigning an array...
Posted: Wed Nov 19, 2003 11:04 pm
I'm afraid I might figure this out after I post it ( it always happens that way... ), but i'll post it anyways cuz i'm stuck heh.
Basically, what i'm trying to do is determine the number of occurances in a database of specific browsers. Some may say "good god, ugly code", well, it works ( well until i put this unset function in it ), so for now til i catch up with the rest of you, it will have to do
anyways, on to the problem and the code!
What i'm trying to do is, set an array of possible strings for browser types. I query the table looking for this string, and then output the result.
After that, I go through the result, and find every instance of where the # of rows of the count is 0, and then unset that array ( so that I can put these values into a bar chart without having white spaces .. ).
so, i tried this code, but upon compiling and trying to echo out the result, i just get a blank page result, but if i take the unset out, it works fine ( except it still posts the values with a 0 in it ).
also, you might ask "why are you trying to dump the array??? Just rename the result to another array !" well, yeah i know. but the fewer times i have to switch variables, the less i'm gonna have to rewrite code...
plus, i know this is possible, it's just breaking my brain trying to figure it out. anyways, here is the code, maybe you can see where i'm screwing up at :
I should also note, that in place of the actual Moz[0] array definition call, i also tried $i for each of them to see if maybe i could just loop through and define them on the fly. unfortunately, same results
Last edit, I also tried the Break statement in each *if* clause... i just left the first one in there for testing purposes...
Basically, what i'm trying to do is determine the number of occurances in a database of specific browsers. Some may say "good god, ugly code", well, it works ( well until i put this unset function in it ), so for now til i catch up with the rest of you, it will have to do
anyways, on to the problem and the code!
What i'm trying to do is, set an array of possible strings for browser types. I query the table looking for this string, and then output the result.
After that, I go through the result, and find every instance of where the # of rows of the count is 0, and then unset that array ( so that I can put these values into a bar chart without having white spaces .. ).
so, i tried this code, but upon compiling and trying to echo out the result, i just get a blank page result, but if i take the unset out, it works fine ( except it still posts the values with a 0 in it ).
also, you might ask "why are you trying to dump the array??? Just rename the result to another array !" well, yeah i know. but the fewer times i have to switch variables, the less i'm gonna have to rewrite code...
plus, i know this is possible, it's just breaking my brain trying to figure it out. anyways, here is the code, maybe you can see where i'm screwing up at :
Code: Select all
<?php
// array of possible strings
$Mozilla = array('Netscape/7.0%','Mozilla/6%','Mozilla/5%','Mozilla/4%', 'NSPlayer/4%','NSPlayer/7%','NSPlayer/9%');
#####################
## Arrays to be called later ##
#####################
$Moz=array();
$Moz_Found=array();
####################
## Start the query process ##
## ..looping for each string ##
####################
for($i=0; $i<=7; $i++)
{
$sql = "select count(UserAgent) from log where (UserAgent LIKE '".$Mozilla[$i]."')";
$result = mysql_query($sql) or die(MySQL_Error());
$row = mysql_fetch_assoc($result);
###########################
## If we find something, process it ##
###########################
while($row = mysql_fetch_assoc($result))
{
foreach($row['count(UserAgent)'] as $found)
{
$Moz_Found[] = $found;
}
switch($Mozilla[$i])
{
case 'Netscape/7.0%' :
if ($Moz_Found[0] =='0')
{
unset($Moz_Found[0]);
unset($Moz[0]);
break;
}
$Moz[0] = 'Mozilla 7.0';
break;
case 'Mozilla/6%' :
if ($Moz_Found[1] =='0')
{
unset($Moz_Found[1]);
unset($Moz[1]);
}
else
{
$Moz[1] = 'Mozilla 6.0';
}
break;
case 'Mozilla/5%' :
if ($Moz_Found[2] =='0')
{
unset($Moz_Found[2]);
unset($Moz[2]);
}
else
{
$Moz[2] = 'Mozilla 5.0';
}
break;
case 'Mozilla/4%' :
if ($Moz_Found[3] =='0')
{
unset($Moz_Found[3]);
unset($Moz[3]);
}
else
{
$Moz[3] = 'Mozilla 4.0';
}
break;
case 'NSPlayer/4%' :
if ($Moz_Found[4] =='0')
{
unset($Moz_Found[4]);
unset($Moz[4]);
}
else
{
$Moz[4] = 'NSPlayer 4.0';
}
break;
case 'NSPlayer/7%' :
if ($Moz_Found[5] =='0')
{
unset($Moz_Found[5]);
unset($Moz[5]);
}
else
{
$Moz[5] = 'NSPlayer 7.0';
}
break;
case 'NSPlayer/9%' :
if ($Moz_Found[6] =='0')
{
unset($Moz_Found[6]);
unset($Moz[6]);
}
else
{
$Moz[6] = 'NSPlayer 9.0';
}
break;
}
}
}
########################
## Echo out any results we find ##
########################
foreach($Moz as $harhar)
{
echo $harhar;
echo ' was Found';
}
?>I should also note, that in place of the actual Moz[0] array definition call, i also tried $i for each of them to see if maybe i could just loop through and define them on the fly. unfortunately, same results
Last edit, I also tried the Break statement in each *if* clause... i just left the first one in there for testing purposes...