Jump to content

finding multiple data in arrays


beyondflash

Recommended Posts

I have multiple arrays pulled from a mysql database. (I will put the code below).

The 2 conditions I have to meet is if the ip address is duplicated in the table and if the duplications between the ip addresses are over 1hr appart. If they are not over 1hr appart, I assign a dblclick varriable to incriment.....else add to a single click array.

Here is the code I have been working with so far:

 

$mgmat = "SELECT * FROM manhattangmat WHERE month = '$month' AND year = '$year' ORDER BY ip ASC";

$mgmat_result = mysql_query($mgmat) or die('Query failed: ' . mysql_error());

$mgmat_row = mysql_fetch_assoc($mgmat_result);

$i = 0;

do {

$mgmat_ID[$i] = $mgmat_row['ID'];

$mgmat_target[$i] = $mgmat_row['target'];

$mgmat_url[$i] = $mgmat_row['url'];

$mgmat_date[$i] = $mgmat_row['date'];

$mgmat_year[$i] = $mgmat_row['year'];

$mgmat_month[$i] = $mgmat_row['month'];

$mgmat_time[$i] = $mgmat_row['time'];

$mgmat_ip[$i] = $mgmat_row['ip'];

$mgmat_browser[$i] = $mgmat_row['browser'];

$mgmat_referer[$i] = $mgmat_row['referer'];

$mgmat_rawtime[$i] = $mgmat_row['rawtime'];

$i++;

} while ($mgmat_row = mysql_fetch_assoc($mgmat_result));

$mgmat_dblclick = 0;

$totalmgmatRawClicks = sizeof($mgmat_ID);

//calculate dbl clicks for mgmat

for($i=0;$i<=sizeof($mgmat_ID);$i++){

if($mgmat_ip[$i]==$mgmat_ip[$i-1] && $mgmat_rawtime[$i] > $mgmat_rawtime[$i-1]-(60*60))

{

$mgmat_dblclick++;

}else{

$s_mgmat_ID[$i] = $mgmat_ID[$i];

$s_mgmat_target[$i] = $mgmat_target[$i];

$s_mgmat_url[$i] = $mgmat_url[$i];

$s_mgmat_date[$i] = $mgmat_date[$i];

$s_mgmat_year[$i] = $mgmat_year[$i];

$s_mgmat_month[$i] = $mgmat_month[$i];

$s_mgmat_time[$i] = $mgmat_time[$i];

$s_mgmat_ip[$i] = $mgmat_ip[$i];

$s_mgmat_browser[$i] = $mgmat_browser[$i];

$s_mgmat_referer[$i] = $mgmat_referer[$i];

}

}

 

as you can see I am only checking the current index vs. the previous index...what I need to do is check to see if the ip is in the database more than once and if it is, make sure they are over an hour appart (saved in the db as raw time()).

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/158821-finding-multiple-data-in-arrays/
Share on other sites

I have multiple arrays pulled from a mysql database. (I will put the code below).

The 2 conditions I have to meet is if the ip address is duplicated in the table and if the duplications between the ip addresses are over 1hr appart. If they are not over 1hr appart, I assign a dblclick varriable to incriment.....else add to a single click array.

Here is the code I have been working with so far:

 

$mgmat = "SELECT * FROM manhattangmat WHERE month = '$month' AND year = '$year' ORDER BY ip ASC";
$mgmat_result = mysql_query($mgmat) or die('Query failed: ' . mysql_error());
$mgmat_row = mysql_fetch_assoc($mgmat_result);
$i = 0;
do {
		$mgmat_ID[$i] = $mgmat_row['ID'];
	$mgmat_target[$i] = $mgmat_row['target'];
	$mgmat_url[$i] = $mgmat_row['url'];
	$mgmat_date[$i] = $mgmat_row['date'];
	$mgmat_year[$i] = $mgmat_row['year'];
	$mgmat_month[$i] = $mgmat_row['month'];
	$mgmat_time[$i] = $mgmat_row['time'];
	$mgmat_ip[$i] = $mgmat_row['ip'];
	$mgmat_browser[$i] = $mgmat_row['browser'];
	$mgmat_referer[$i] = $mgmat_row['referer'];
	$mgmat_rawtime[$i] = $mgmat_row['rawtime'];
	$i++;
} while ($mgmat_row = mysql_fetch_assoc($mgmat_result)); 
$mgmat_dblclick = 0;
$totalmgmatRawClicks = sizeof($mgmat_ID);
//calculate dbl clicks for mgmat
for($i=0;$i<=sizeof($mgmat_ID);$i++){
if($mgmat_ip[$i]==$mgmat_ip[$i-1] && $mgmat_rawtime[$i] > $mgmat_rawtime[$i-1]-(60*60))
	{
	$mgmat_dblclick++;
}else{
	$s_mgmat_ID[$i] = $mgmat_ID[$i];
	$s_mgmat_target[$i] = $mgmat_target[$i];
	$s_mgmat_url[$i] = $mgmat_url[$i];
	$s_mgmat_date[$i] = $mgmat_date[$i];
	$s_mgmat_year[$i] = $mgmat_year[$i];
	$s_mgmat_month[$i] = $mgmat_month[$i];
	$s_mgmat_time[$i] = $mgmat_time[$i];
	$s_mgmat_ip[$i] = $mgmat_ip[$i];
	$s_mgmat_browser[$i] = $mgmat_browser[$i];
	$s_mgmat_referer[$i] = $mgmat_referer[$i];
}
}

 

as you can see I am only checking the current index vs. the previous index...what I need to do is check to see if the ip is in the database more than once and if it is, make sure they are over an hour appart (saved in the db as raw time()).

 

Thanks in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.