Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/01/2004, 09:25
Avatar de epplestun
epplestun
 
Fecha de Ingreso: octubre-2001
Mensajes: 1.621
Antigüedad: 22 años, 6 meses
Puntos: 5
Problemilla que no soluciono :-(

Buenas, tengo un pequeño problema en este code, el metodo getForums() me funciona bien cuando lo uso en case "foros" pero cuando lo uso en ver_foros me devuelve los datos correctamente, pero a parte al final de todo me inserta un numero, y no se por que o bueno no soy capaz de encontrar el fallo jeje esta claro que el fallo tiene que estar al hacer return $this->datos; pero bueno ... a ve si alguien me puede ayudar

Código PHP:
<?PHP
/*
   +--------------------------------------------------------------------+
   | DForum v.0.0.1                                                     |
   +--------------------------------------------------------------------+
   | Copyright (c) 2003 Dikode                                          |
   +--------------------------------------------------------------------+
   | This source file is subject to version 2.02 of the PHP license,    |
   | that is bundled with this package in the file LICENSE, and is      |
   | available at through the world-wide-web at                         |
   | [url]http://www.php.net/license/2_02.txt.[/url]                               |
   | If you did not receive a copy of the PHP license and are unable to |
   | obtain it through the world-wide-web, please send a note to        |
   | [email][email protected][/email] so we can mail you a copy immediately.             |
   +--------------------------------------------------------------------+
   | Authors: Ivan Rodriguez Espada   <[email protected]>          |
   +--------------------------------------------------------------------+
*/

class DForum {
    var 
$host;
    var 
$user;
    var 
$pass;
    var 
$BBDD;
    var 
$id_connection;
    var 
$datos = array();
    
    function 
DForum($host$user$pass) {
        
$this->host $host;
        
$this->user $user;
        
$this->pass $pass;
        
$this->BBDD "DForum";
        
$this->id_connection mysql_connect($this->host$this->user$this->pass) or die (mysql_error());
        
mysql_select_db($this->BBDD$this->id_connection) or die (mysql_error());
        return 
$this->id_connection;
    }
    
    function 
getForums($SQL   "SELECT id_forum, forum_title FROM forums") {
        
$expresion "from ([a-z0-9_]+)";        
        if(
eregi ($expresion$SQL$nombre)) {
            
$tabla $nombre[1];
        }
        
        
$celdas    mysql_list_fields($this->BBDD$tabla$this->id_connection);
        
$columnas  mysql_num_fields($celdas);
        
$campos    = array();
        
$dato      = array();
        
        for (
$i 0$i $columnas$i++) {
            
$campos[] = mysql_field_name($celdas$i);
        }
        
        
$consulta  mysql_query($SQL$this->id_connection) or die(mysql_error());
        
$registros mysql_num_rows($consulta) or die(mysql_error());
        
        for(
$i 0$i $registros$i++) {
            while(
$campo mysql_fetch_array($consulta)) {
                for(
$i 0$i count($campos); $i++) {
                    
$dato[$i] = $campo[$campos[$i]];
                }
                
$this->datos[] = $dato;
            }
        }
        
        return 
$this->datos;
    }
    
    function 
getForumInfo($id_forum) {
        
$id_forum $id_forum-1;
        
$SQL      "SELECT autor, data FROM messages WHERE forum = $id_forum ORDER BY data DESC LIMIT 0, 1";
        
$query mysql_query($SQL$this->id_connection) or die (mysql_error());
        while(
$d mysql_fetch_array($query)) {
            return 
$d["autor"] . "-" date("d-m-Y"$d["data"]) . "<br>";
        }
    }
    
    function 
countForumMessages($id_forum) {
        
$id_forum $id_forum-1;
        
$SQL      "SELECT    id_message FROM messages WHERE forum = $id_forum AND id_forum = 0";
        
$query mysql_query($SQL$this->id_connection) or die (mysql_error());
        return 
mysql_num_rows($query);
    }
    
    function 
getForumMessages($forum) {
        
$forum $forum 1;
        
$SQL   "SELECT id_message, autor, title, message, data, answers, id_forum, forum FROM messages WHERE id_forum = 0 AND forum = $forum ORDER BY data DESC";
        return 
$this->getForums($SQL);
    }
}

$f = new DForum("host""user""pass");

if(empty(
$_GET['accion'])) {
    
$accion "foros";
} else {
    
$accion $_GET['accion'];
}

switch(
$accion) {
    case 
"foros":
        echo 
"<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\">";
        echo 
"<tr><td width=\"200\">Foro</td><td width=\"50\">Mensajes</td><td width=\"200\">Último mensjae</td></tr>";
        echo 
"</table>";
        echo 
"<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\">";
        foreach(
$f->getForums() aS $F) {
            echo 
"<tr><td width=\"200\"><a href=\"ver.php?id_foro=$F[0]&accion=ver_foro\">" .$F[1] . "</a></td><td width=\"50\">".$f->countForumMessages($F[0])."</td><td width=\"200\">" .             $f->getForumInfo($F[0]) . "</td></tr>";
        }
        echo 
"</table>";
        break;
    case 
"ver_foro":
        
$datos $f->getForumMessages($_GET['id_foro']);
        for(
$i 0$i count($datos); $i++) {
            echo 
$datos[$i][1] . "<br>";
        }
        break;
    default: break;
}
?>
__________________
Usuario registrado de Linux #288725