Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/02/2014, 19:41
juandedios
 
Fecha de Ingreso: mayo-2003
Ubicación: Lima
Mensajes: 967
Antigüedad: 21 años, 10 meses
Puntos: 8
Clase para mostrar consulta

Hola, tengo un problema cuando quiero mostrar los datos de una consulta, tengo una clase que va así:
Código PHP:
Ver original
  1. require_once 'dbConnect.php';
  2.  
  3. class cColegios {
  4.    
  5.     static private $instance;
  6.     private $conn;
  7.     private $result;
  8.     const TABLA_COLEGIOS      = "colegios";
  9.    
  10.     //Constructor
  11.     private function __construct() {
  12.         $this->conn = Database::singleton();
  13.     }
  14.    
  15.     public static function singleton() {
  16.         if (!isset(self::$instance)) {
  17.             $miclase = __CLASS__;
  18.             self::$instance = new $miclase;
  19.         }
  20.  
  21.         return self::$instance;
  22.     }
  23.    
  24.     public function showColegiosRegistrados() {
  25.         try {
  26.             $sql = "SELECT codigo, ruc, nombre, telefono1, email
  27.                    FROM " . self::TABLA_COLEGIOS . "
  28.                    WHERE estado = 1";
  29.             $query = $this->conn->prepare( $sql );
  30.             $query->execute();
  31.            
  32.             if ( $query->rowCount() > 0 ) {
  33.                 while ( $row = $query->fetch( PDO::FETCH_NUM ) ) {
  34.                     $this->result .= '<tr>
  35.                                        <td>' . $row[ 1 ] . '</td>
  36.                                        <td>' . $row[ 2 ] . '</td>
  37.                                        <td>' . $row[ 3 ] . '</td>
  38.                                        <td>' . $row[ 4 ] . '</td>
  39.                                        <td>
  40.                                            <a href="#" class="btn btn-danger btn-xs" data-toggle="tooltip" data-placement="top" title="No Contactado">NC</a>
  41.                                            <a href="#" class="btn btn-warning btn-xs md-trigger" data-modal="detailModalRegistrado" data-toggle="tooltip" data-placement="top" title="Ver detalles"><i class="fa fa-search"></i></a>
  42.                                        </td>
  43.                                      </tr>';
  44.                 }
  45.             }
  46.             else {
  47.                 $this->result = '<tr><td colspan="5">No hay colegios registrados.</td></tr>';
  48.             }
  49.         }
  50.         catch ( PDOExeption $e ) {
  51.             $this->result = 'Error: ' . $e->getMessage();
  52.         }
  53.        
  54.         return $this->result;
  55.     }
  56.    
  57. }
Y lo uso así:
Código PHP:
Ver original
  1. <?php
  2. require_once 'inc/class/colegios.php';
  3. $vCole = cColegios::singleton();
  4. ?>
  5. <div class="table-responsive">
  6.     <table class="table table-hover table-striped">
  7.         <thead>
  8.             <tr>
  9.                 <th>RUC</th>
  10.                 <th>Nombre</th>
  11.                 <th>Tel&eacute;fono</th>
  12.                 <th>Email</th>
  13.                 <th>Estado</th>
  14.             </tr>
  15.         </thead>
  16.         <tbody>
  17.             <?php echo $vCole->showColegiosRegistrados(); ?>
  18.         </tbody>
  19.     </table>
  20. </div>
Las filas si las muestra, pero arriba de la tabla me sale un mensaje que dice así:
Código PHP:
Ver original
  1. Notice: Array to string conversion in F:\xampp\htdocs\colegios\webmaster\inc\class\colegios.php on line 38
__________________
El aprendiz.