<?php
require_once("comun/conexion3.php");
$linki=con_impo(); 
$q = strtolower($_GET["q"]);
if (!$q) return;
// and international_name like '$txtnombre_del_puerto%'

$sql = "SELECT * FROM  puertos_k where ((international_name like '$q%' OR name_without_diacritics like '$q%') or (country like '%$q%')) and country<>'' AND LENGTH(TRIM(location_code))=5 order by international_name";
//SELECT * FROM contact  where id = '$txtidc'  order by name, function"
$rsd = mysqli_query($linki,$sql);
if(mysqli_num_rows($rsd)<1){
$sql = "SELECT * FROM  puertos_k WHERE 
( CONCAT_WS(', ',international_name,country) like '$q%' OR CONCAT_WS(', ',name_without_diacritics,country)  like '$q%') 
AND LENGTH(TRIM(location_code))=5 order by international_name";
$rsd = mysqli_query($linki,$sql);	
}
while($rs = mysqli_fetch_array($rsd)) {
	//$mostrar = ($rs['international_name']!='' ? $rs['international_name'] : $rs["name_without_diacritics"]) .'-'.strtoupper($rs['country']);
	$cname = strtoupper($rs['country']);
	$location_code = strtoupper($rs['location_code']);
	//$nombre_del_puerto = strtoupper(($rs['international_name']!='' ? $rs['international_name'] : $rs["name_without_diacritics"]));
	$nombre_del_puerto = trim($rs["international_name"]); //$rs["name_without_diacritics"]==$rs['international_name'] ? 
	//(trim($rs["name_without_diacritics"])!='' ? trim($rs["name_without_diacritics"]) : ) : trim($rs["name_without_diacritics"]).', '.trim($rs["international_name"]);
	$mostrar=$location_code.'-'.$nombre_del_puerto.'-'.strtoupper($rs['country']);
	print "$mostrar|$cname|$nombre_del_puerto|$location_code\n";
}
 
?>

