Exemplo n.º 1
0
function load()
{
    $id_plat_cat = array();
    $platos_cat = array();
    $platos_obj = array();
    $platos_obj_r = array();
    $platos_rango = array();
    $i = 0;
    $j = 0;
    $k = 0;
    if (!isset($_POST) || !isset($_SESSION['user_bd13']) || $_SESSION['user_bd13']->rol != 1) {
        header('Location: ../login.php');
        exit;
    } else {
        $db = new phpDB();
        $db->connect();
        if (isset($_POST['filtro_busqueda_categ'])) {
            $categoria = $_POST['categoria'];
            $query = "SELECT * FROM categoria WHERE nombre_categoria LIKE '%{$categoria}%'";
            $db->exec($query, array());
            $rs1 = $db->fobject();
            if (is_null($rs1)) {
                echo '<div class="alert alert-info"> No hay resultados para la búsqueda</div>';
                return;
            } else {
                do {
                    $id_plat_cat[$i] = $rs1->id_categoria;
                    $i++;
                } while ($db->nextRow());
                foreach ($id_plat_cat as $key => $value) {
                    $query2 = "SELECT * FROM plato WHERE id_categoria = '{$value}'";
                    $db->exec($query2, array());
                    do {
                        $rs2 = $db->fobject();
                        $platos_cat[$k] = $rs2->nombre_plato;
                        $platos_obj[$k] = $rs2;
                        $k++;
                    } while ($db->nextRow());
                }
            }
        }
        if (isset($_POST['filtro_busqueda_rango'])) {
            $rango_start = $_POST['start'];
            $rango_end = $_POST['end'];
            if ($rango_start > $rango_end || $rango_start == 0 && $rango_end == 0) {
                echo '<div class="alert alert-danger"> Se ingreso mal los rangos de búsqueda</div>';
                return;
            }
            $query3 = "SELECT * FROM plato WHERE precio BETWEEN {$rango_start} AND {$rango_end}";
            $db->exec($query3, array());
            do {
                $rs3 = $db->fobject();
                $platos_rango[$j] = $rs3->nombre_plato;
                $platos_obj_r[$j] = $rs3;
                $j++;
            } while ($db->nextRow());
        }
        if (isset($_POST['filtro_busqueda_categ']) && isset($_POST['filtro_busqueda_rango'])) {
            $result = array();
            $indice = 0;
            foreach ($platos_obj as $key => $value) {
                foreach ($platos_obj_r as $key2 => $value2) {
                    if ($value->id_plato == $value2->id_plato) {
                        $result[$indice] = $value;
                        $indice++;
                    }
                }
            }
            //$result = array_intersect($platos_obj, $platos_obj_r);
            ?>
            <div class="well table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Nombre</th>
                            <th>Precio</th>
                            <th>Cantidad</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
            foreach ($result as $key => $pl) {
                ?>
                            <tr>
                                <td>
                                    <button class="btn btn-link" data-toggle="modal" data-target="#myModal<?php 
                echo $pl->id_plato;
                ?>
">
                                        <?php 
                echo $pl->nombre_plato;
                ?>
                                    </button>
                                    <?php 
                include 'modal_busqueda.php';
                ?>
                                </td>
                                <td> $
                                    <?php 
                echo $pl->precio . "<br>";
                ?>
                                </td>
                                <td>
                                    <form method="post" id ="cant<?php 
                echo $pl->id_plato;
                ?>
" action="handlers/add_carrito_handler.php?idprod=<?php 
                echo $pl->id_plato;
                ?>
&nombre=<?php 
                echo $pl->nombre_plato;
                ?>
&precio=<?php 
                echo $pl->precio;
                ?>
&dir=carta.php&descrip=<?php 
                echo str_replace(' ', '+', $pl->descripcion);
                ?>
">
                                        <input type = "number" min = "1" max = "20" step = "1" value = "1" size = "3" name="cantidad"> 
                                        <button type="submit" class="btn btn-success btn-xs">Agregar</button>
                                    </form>
                                </td>
                            </tr>
                        <?php 
            }
            ?>
                    </tbody>
                </table>
            </div>
            <?php 
        } else {
            if (!empty($platos_cat)) {
                ?>
                <div class="well table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Nombre</th>
                                <th>Precio</th>
                                <th>Cantidad</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                foreach ($platos_cat as $key => $pl) {
                    ?>
                                <tr>
                                    <td>
                                        <button class="btn btn-link" data-toggle="modal" data-target="#myModal<?php 
                    echo $platos_obj[$key]->id_plato;
                    ?>
">
                                            <?php 
                    echo $platos_obj[$key]->nombre_plato;
                    ?>
                                        </button>
                                        <?php 
                    include 'descripcionModal.php';
                    ?>
                                    </td>
                                    <td> $
                                        <?php 
                    echo $platos_obj[$key]->precio . "<br>";
                    ?>
                                    </td>
                                    <td>
                                        <form method="post" id ="cant<?php 
                    echo $platos_obj[$key]->id_plato;
                    ?>
" action="handlers/add_carrito_handler.php?idprod=<?php 
                    echo $platos_obj[$key]->id_plato;
                    ?>
&nombre=<?php 
                    echo $platos_obj[$key]->nombre_plato;
                    ?>
&precio=<?php 
                    echo $platos_obj[$key]->precio;
                    ?>
&dir=carta.php&descrip=<?php 
                    echo str_replace(' ', '+', $platos_obj[$key]->descripcion);
                    ?>
">
                                            <input type = "number" min = "1" max = "20" step = "1" value = "1" size = "3" name="cantidad"> 
                                            <button type="submit" class="btn btn-success btn-xs">Agregar</button>
                                        </form>
                                    </td>
                                </tr>
                            <?php 
                }
                ?>
                        </tbody>
                    </table>
                </div>
                <?php 
            } elseif (!empty($platos_rango)) {
                ?>
                <div class="well table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Nombre</th>
                                <th>Precio</th>
                                <th>Cantidad</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                foreach ($platos_rango as $key => $pl) {
                    ?>
                                <tr>
                                    <td>
                                        <button class="btn btn-link" data-toggle="modal" data-target="#myModal<?php 
                    echo $platos_obj_r[$key]->id_plato;
                    ?>
">
                                            <?php 
                    echo $platos_obj_r[$key]->nombre_plato;
                    ?>
                                        </button>
                                        <?php 
                    include 'descripcionModal.php';
                    ?>
                                    </td>
                                    <td> $
                                        <?php 
                    echo $platos_obj_r[$key]->precio . "<br>";
                    ?>
                                    </td>
                                    <td>
                                        <form method="post" id ="cant<?php 
                    echo $platos_obj_r[$key]->id_plato;
                    ?>
" action="handlers/add_carrito_handler.php?idprod=<?php 
                    echo $platos_obj_r[$key]->id_plato;
                    ?>
&nombre=<?php 
                    echo $platos_obj_r[$key]->nombre_plato;
                    ?>
&precio=<?php 
                    echo $platos_obj_r[$key]->precio;
                    ?>
&dir=carta.php&descrip=<?php 
                    echo str_replace(' ', '+', $platos_obj_r[$key]->descripcion);
                    ?>
">
                                            <input type = "number" min = "1" max = "20" step = "1" value = "1" size = "3" name="cantidad"> 
                                            <button type="submit" class="btn btn-success btn-xs">Agregar</button>
                                        </form>
                                    </td>
                                </tr>
                            <?php 
                }
                ?>

                        </tbody>
                    </table>
                </div>
                <?php 
            } else {
                echo '<div class="alert alert-info"> Marque una opción de búsqueda para iniciar el proceso</div>';
            }
        }
    }
}
Exemplo n.º 2
0
<?php

$db = new phpDB();
$db->connect();
$query = "SELECT * FROM categoria";
$db->exec($query, array());
?>


<div class="table-responsive">
    <table class="table table-hover table-bordered">
        <tbody>
            <?php 
do {
    $rs = $db->fobject();
    ?>
                <tr>
                    <td class="capitalize"><?php 
    echo $rs->nombre_categoria;
    ?>
</td>
                </tr>
            <?php 
} while ($db->nextRow());
?>
        </tbody>
    </table>
</div>