<?php

if (session_id() == "")
    session_start();
$com = "AS";
include("DMMYSQLG.php");
//include("DSA1000.php");

$resultado = [];
$textBus = mysqli_real_escape_string($con,$_REQUEST['term']);
if (trim($textBus) != '') {
    //al uncionmysqli_query ya ejecuta la consulta
    @$sq_retrieve = mysqli_query($con ,"SELECT DISTINCT(n_reg),agdescrip FROM valeryus07 WHERE modulo='" . $_SESSION['mod_sis'] . "' AND agdescrip like '%$textBus%' 
             OR  modulo='" . $_SESSION['mod_sis'] . "' AND n_reg like '%$textBus%'  ORDER BY n_reg");
    //$q = mysqli_real_escape_string($con,$_GET["q"]);
//$limit= mysqli_real_escape_string($con,$_GET["limit"]);
//if($_GET['tipBus']=='d')
//	$sq_invent=mysqli_query($con ,"SELECT agdescrip,n_reg,cod_var FROM valeryus07 WHERE modulo='".$_SESSION['mod_sis']."' AND agdescrip like '%$q%' order by agdescrip limit $limit");
//elseif($_GET['tipBus']=='c')
//		$sq_invent=mysqli_query($con ,"SELECT * FROM valeryus07 WHERE modulo='".$_SESSION['mod_sis']."' AND n_reg like '%$q%' OR cod_var='$q' order by n_reg limit $limit");
//while($dt_invent=mysqli_fetch_array(@$sq_retrieve)){
    // @$sql = mysqli_query($con ,$sq_retrieve);
}while (@$reg = mysqli_fetch_array($sq_retrieve)) {
        $row["label"] = "(" . $reg['n_reg'] . ")" . $reg['agdescrip'];
        $row["agdescrip"] = $reg['agdescrip'];
        $row["id"] = $reg['n_reg'];
        $row["value"] = $reg['agdescrip'];

        $resultado[] = $row;
    }
//	echo "$dt_invent['agdescrip']|$dt_invent['n_reg']\n";
    echo json_encode($resultado);

?>