<?php

    $id = isset($_REQUEST['plan_id']) ? $_REQUEST['plan_id'] : '';
    
    $result = array();
    
    include '../rdb/conn.php';
    $where ="";
    if ($id <>'') {$where .= " and tipo_plan_mustreo_id = $id "; }

    $sql = "select count(*) from productos   ";
    $sql .= "where 1  ";
    $sql.= $where;
    
    $rs = mysqli_query( $conn,$sql);
    $row = mysqli_fetch_row($rs);
    $result["total"] = $row[0];
    
    if ($result["total"] === 0) {exit;}  

    $sql = "select * from productos  ";
    $sql .= "where 1  ";
    $sql.= $where;
    $sql.= "order by nombre";
    
    $rs = mysqli_query( $conn,$sql);
    
    $items = array();
    while($row = mysqli_fetch_object($rs)){
        array_push($items, $row);
    }

    echo json_encode($items);
    
?>