function get_ip_id($ip_address) { $mysql['ip_address'] = mysql_real_escape_string($ip_address); $ip_sql = "SELECT ip_id FROM 202_ips WHERE ip_address='" . $mysql['ip_address'] . "'"; $ip_result = _mysql_query($ip_sql); $ip_row = mysql_fetch_assoc($ip_result); if ($ip_row) { //if this ip already exists, return the ip_id for it. $ip_id = $ip_row['ip_id']; return $ip_id; } else { //else if this doesn't exist, insert the new iprow, and return the_id for this new row we found //but before we do this, we need to grab the location_id $location_id = INDEXES::get_location_id($ip_address); $mysql['location_id'] = mysql_real_escape_string($location_id); $ip_sql = "INSERT INTO 202_ips SET ip_address='" . $mysql['ip_address'] . "', location_id='" . $mysql['location_id'] . "'"; $ip_result = _mysql_query($ip_sql); //($ip_sql); $ip_id = mysql_insert_id(); return $ip_id; } }