Location: PHPKode > projects > YASeMI > yasemi_0.1/gs/host_count.php
<?php

	// THE SCRIPT FOR CONNECTING TO THE DATABASE
	include '../gs/dbc.php';

	// CONNECTING TO THE DATABASE
	$link_id = db_connect();

	// FETCH THE SUBNETS
	$query = "SELECT settings_subnet 
				FROM settings
				";
				
	// EXECUTES THE QUERY
	$result = mysql_query($query) or die(mysql_error().'<br> SQL:'.$query);

	$total_hosts = 0;
	while ($row = mysql_fetch_row($result)) {

		// FETCH THE NUMBER OF IP'S PER SUBNET
		$query2 = "SELECT count(distinct ipv4_src_addr)
					FROM record
					WHERE inet_ntoa(ipv4_src_addr) LIKE '".$row[0].".%'
					";

		// EXECUTES THE QUERY
		$result2 = mysql_query($query2) or die(mysql_error().'<br> SQL:'.$query);
			
		while ($row2 = mysql_fetch_row($result2)) {
			// CALCULATE TOTAL HOSTS
			$total_hosts += $row2[0];
					
		}
	
	}

	// INSERT THE CALCULATED TOTAL NUMBER OF HOSTS
	$query = "UPDATE settings 
				SET settings_nohosts = '".$total_hosts."'
				WHERE settings_id = 1
				";
	
	$result = mysql_query($query) or die(mysql_error().'<br> SQL:'.$query);
	
	// CLOSE THE DB CONNECTION
	mysql_close($link_id);
	
	header("Location: ../settings.php");

?>
Return current item: YASeMI