Foros del Web » Programando para Internet » PHP »

PHP, SQL y Templates

Estas en el tema de PHP, SQL y Templates en el foro de PHP en Foros del Web. Buenos dias a todos!! Pues bien, mi problema es el siguiente: En una base de datos "X" tengo tres tablas "A, B, y C", con ...
  #1 (permalink)  
Antiguo 21/07/2008, 13:29
Avatar de punk-devil  
Fecha de Ingreso: febrero-2008
Ubicación: Tuxtla Gutiérrez, Chiapas, Mexico
Mensajes: 19
Antigüedad: 16 años, 2 meses
Puntos: 3
PHP, SQL y Templates

Buenos dias a todos!!

Pues bien, mi problema es el siguiente:

En una base de datos "X" tengo tres tablas "A, B, y C", con 20 datos cada uno, y necesito hacer una consulta para mostrar el contenido de A y de B, pero utilizando un template.

Este es class ke uso. (classTemplate.php)

Código PHP:
<?php
class Template {
    var 
$vars/// Holds all the template variables

    
    
function Template($file null) {
        
$this->file $file;
    }

   
    function 
set($name$value) {
        
$this->vars[$name] = is_object($value) ? $value->fetch() : $value;
    }

    
    function 
fetch($file null) {
        if(!
$file$file $this->file;

        
extract($this->vars);          // Extract the vars to local namespace
        
ob_start();                    // Start output buffering
        
include($file);                // Include the file
        
$contents ob_get_contents(); // Get the contents of the buffer
        
ob_end_clean();                // End buffering and discard
        
return $contents;              // Return the contents
    
}
}


class 
CachedTemplate extends Template {
    var 
$cache_id;
    var 
$expire;
    var 
$cached;

    function 
CachedTemplate($cache_id null$expire 900) {
        
$this->Template();
        
$this->cache_id $cache_id 'cache/' md5($cache_id) : $cache_id;
        
$this->expire   $expire;
    }


    function 
is_cached() {
        if(
$this->cached) return true;

        
// Passed a cache_id?
        
if(!$this->cache_id) return false;

        
// Cache file exists?
        
if(!file_exists($this->cache_id)) return false;

        
// Can get the time of the file?
        
if(!($mtime filemtime($this->cache_id))) return false;

        
// Cache expired?
        
if(($mtime $this->expire) < time()) {
            @
unlink($this->cache_id);
            return 
false;
        }
        else {

            
$this->cached true;
            return 
true;
        }
    }


    function 
fetch_cache($file) {
        if(
$this->is_cached()) {
            
$fp = @fopen($this->cache_id'r');
            
$contents fread($fpfilesize($this->cache_id));
            
fclose($fp);
            return 
$contents;
        }
        else {
            
$contents $this->fetch($file);

            
// Write the cache
            
if($fp = @fopen($this->cache_id'w')) {
                
fwrite($fp$contents);
                
fclose($fp);
            }
            else {
                die(
'Unable to write cache.');
            }

            return 
$contents;
        }
    }
}


?>
Este es el template x ejemplo (index.tpl)

Código HTML:
<html>
    <head>
        <title><?=$title;?></title>
        <link href="style.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
        
        <?=$content;?>

    </body>
</html> 
y el index.php

Código PHP:
<?php
require_once('classTemplate.php');
//requiere('db.php');

$tpl = & new Template('index.tpl'); // this is the outer template
$tpl->set('title''User List');


// Aca la consulta para la base de datos



echo $tpl->fetch('index.tpl');
?>
Lo ke sucede es ke he probado con muchisimos bucles, y aun no puedo hacerlo funcionar!!!

si hago un foreach en index.tpl, me aparece solo el primer caracter de la tabla repetido el numero de veces de datos ke hay.... osea ke si hay 20 datos.... y son dos tablas.... 40 veces...

aun no me explico si el error esta en la forma en la ke hago la consulta (while) o estoy haciendo algo mal con el bucle...

Si alguien puede ayudarme, gracias!!!
  #2 (permalink)  
Antiguo 25/07/2008, 14:42
Avatar de lalogrosz  
Fecha de Ingreso: mayo-2002
Ubicación: Capital Federal
Mensajes: 339
Antigüedad: 21 años, 11 meses
Puntos: 6
Respuesta: PHP, SQL y Templates

Hola, el problema aca no esta en los templates.
Pone tu consulta o bien el ejemplo de lo que estas haciendo xq en lo que pusiste no hay nada reflejado, ni bucles ni nada.

Saludos.
__________________
"Vivir....solo cuesta Vida"
  #3 (permalink)  
Antiguo 05/08/2008, 07:46
 
Fecha de Ingreso: agosto-2008
Mensajes: 5
Antigüedad: 15 años, 8 meses
Puntos: 1
Respuesta: PHP, SQL y Templates

Yo tengo el mismo problema.
Si pudiste resolverlo por favor indicame cómo hiciste.
Muchas Gracias.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:38.