Help does not display data from the foreach smarty table

3

My problem is that it does not show the data of the query friends I would like to know because, by the way I am new programming

this is my index.php

    <?php
    include 'header.php';
        session_start();
        if(isset($_SESSION['rango']) and $_SESSION['rango'] == 4){
                echo 'Funciona';
        }else{
            session_start();
            session_destroy();
            header('location: login.php');
        }

        switch($modo){
            default:
                $db = new Conexion();
                $smarty = new Smarty();
                $sql= $db->query("SELECT * FROM lonas ORDER BY lonas.id_lona DESC");
                $dato = $db->recorrer($sql);
                $smarty->assign("erPrint",$sql);
                $template->display('admin.tpl');
            break;
            case 'subir_archivo': 
                $template->display('upload.tpl');
            break;


        }


    include 'footer.php';

?>

this my header.php

    <?php
    require 'config.php';
    require 'inc/smarty/Smarty.class.php';
    $template = new Smarty();

    $modo = isset($_GET['modo']) ? $_GET['modo'] : 'default';
    switch($modo){
        case 'salir':
                session_start();

                    if(!isset($_SESSION['email'])){

                    }else{
                        session_start();
                        session_destroy();
                        header('location: login.php');
                    }
        break;
    }  
?>

this my config.php file

    class Conexion extends mysqli {
        public function __construct() {
            parent::__construct('localhost','erprint','repass','erprint1');
            $this->query("SET NAMES 'utf8';");
            $this->connect_errno ? die('Error con la conexion') : $x = 'Conectado';
            #echo $x;
            unset($x);
        }

        public function recorrer($y){
            return mysqli_fetch_array($y);
        }
        public function ver($y){
            mysqli_fetch_array($y);
        }

    }
$db = new Conexion();

Finally my admin.tpl file

                       {foreach from=$erPrint item=m}  
                        <div class="tp panel panel-primary">
                            <div class="panel-heading">{$m.nombre_lona}
                                    <div class="dropdown" style="float: right;">
                                      <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                                        <span class="caret"></span>
                                      </button>
                                      <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                                        <li><a href="$modo=eliminar_archivo">Eliminar archivo</a></li>
                                        <li><a href="$modo=renombrar_archivo">Renombrar archivo</a></li>
                                        <li role="separator" class="divider"></li>
                                        <li><a href="?modo=obtener_enlace">Obtener enlace individual</a></li>
                                      </ul>
                                    </div>
                            </div>
                            <div class="panel-body">
                                <img src="{$m.enlace_lona}" alt="" width="210" class="img-thumbnail img-responsive"/>
                            </div>                 
                        </div>
                        {foreachelse}
                        no hay resultados
                        {/foreach}
    
asked by Angel Gutierrez 19.05.2016 в 00:52
source

2 answers

1
  • See if the SELECT returns records making the request from the BBDD.
  • If it returns data, check if it is executing the request (make a var_dump() ).
  • answered by 07.10.2016 в 13:48
    0

    Suddenly I see that in your index you have session_start() below an include. The order session_start() should always go to the beginning, try to put it before the include .

    I leave you with a tip to do debugging in PHP . Whenever you have an error and do not know where you can be, you have the option of displaying the error log on the screen with the following commands:

    ini_set('display_startup_errors', 1);
    ini_set('display_errors', 1);
    error_reporting(-1);
    

    This will show you all the errors and warnings of your code once it is executed, saving you a lot of headaches.

        
    answered by 07.10.2016 в 13:55