Ver Mensaje Individual
  #11 (permalink)  
Antiguo 11/06/2012, 12:01
Blashak
 
Fecha de Ingreso: noviembre-2007
Mensajes: 471
Antigüedad: 16 años, 5 meses
Puntos: 2
Respuesta: obtener todos los datos de una tabla

segun tu me tendria que quedar asi, no???



Código PHP:
Ver original
  1. include('db.php');
  2.  
  3.  
  4. class material extends DB{
  5.  
  6.     private $db;
  7.    
  8.     public $id;
  9.     public $nombre;
  10.     public $referencia;
  11.     public $peso;
  12.     public $tamano;
  13.    
  14.     public function __construct($id_material){
  15.         if($id_material > 0){
  16.            
  17.             $this->db = new DB();
  18.        
  19.             $sql= "
  20.                 SELECT
  21.                     *
  22.                 FROM material
  23.                 WHERE id = ".$id_material."
  24.             ";
  25.            
  26.            
  27.             $this->db->query = $sql;
  28.            
  29.             $t_material  = $this->db->AssocList();
  30.            
  31.             foreach($t_material as $k => $v){
  32.            
  33.                 $this->id = $t_material[$k]['id'];
  34.                 $this->nombre = $t_material[$k]['nombre'];
  35.                 $this->referencia = $t_material[$k]['referencia'];
  36.                 $this->peso = $t_material[$k]['peso'];
  37.                 $this->tamano = $t_material[$k]['tamano'];
  38.             }
  39.            
  40.         }
  41.     }
  42.    
  43.     public function add($Idatos;)
  44.      {
  45.        
  46.         $this->nombre = $Idatos['nombre'];
  47.         $this->referencia = $Idatos['referencia'];
  48.         $this->peso = $Idatos['peso'];
  49.         $this->tamano = $Idatos['tamano'];
  50.  
  51.        
  52.         ;
  53.         $sql= "INSERT INTO material(nombre, referencia, peso, tamano)VALUES(".$this->nombre.", ".$this->referencia.", ".$this->peso.", ".$this->tamano.")" ;
  54.  
  55.         $this->db->query = $sql;
  56.        
  57.         $this->db->InsertData();
  58.        
  59.      }
  60.  
  61. }
  62.  
  63.  
  64. $material = new material(-1);
  65. $material->add($Idatos);