problems reassigning an array...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i think i got it without having to create a table, using some of the theory by Microthick above.

here is what i'm doing now :

Code: Select all

<?php

$sql = "SELECT UserAgent, count(UserAgent) FROM log WHERE (UserAgent LIKE 'Mozilla/4%') Group by UserAgent HAVING count(UserAgent) > 0";
$result = mysql_query($sql) or die(MySQL_Error());
$row = mysql_fetch_assoc($result);

$Mozilla4 = $row['UserAgent'];
$Mozilla4_total = $row['count(UserAgent)'];
echo $Mozilla4_total.' '.$Mozilla4;

?>
*does happy hillbilly dance*




!!!!!!! EDIT !!!!!!!! WOW indeedy, check this out, a much less string of code for all this :

Code: Select all

<?php

$Mozilla = array('Netscape/7%','Mozilla/6%','Mozilla/5%','Mozilla/4%', 'NSPlayer/4%','NSPlayer/7%','NSPlayer/9%');
$Moz = array();
$Moz_total = array();
for($i=0; $i<8; $i++)
{
	$sql = "SELECT UserAgent, count(UserAgent) FROM log WHERE (UserAgent LIKE '".$Mozilla[$i]."') Group by UserAgent HAVING count(UserAgent) > 0";
	$result = mysql_query($sql) or die(MySQL_Error());
	$row = mysql_fetch_assoc($result);
	$Moz[$i] = $row['UserAgent'];
	$Moz_total[$i] = $row['count(UserAgent)'];
}
for($i=0; $i<8; $i++)
{
	echo $Moz_total[$i].' '.$Moz[$i];
	echo '<br />';
}
?>
it hurts to be this good. :twisted:
Post Reply