numOfertas = 0; $this->contador = 0; $this->result = false; $this->curTipo = $tipo; $cuantos = $cuantos * 4; $conn = db_connect(); if($conn) { $query = 'SELECT fab_nombre, fab_id, prod_id, prod_modelo, prod_precio, prod_descripcion, prod_categoria_id, cat_nombre, cat_seccion FROM shoop_prod_ofertas, shoop_productos, shoop_fabricantes, shoop_categorias WHERE oferta_tipo=' . $tipo . (strlen($categoria) ? ' AND oferta_cat_id="' . $categoria .'"': '') . ' AND prod_precio > 0 AND prod_id=oferta_prod_id AND cat_codigo=prod_categoria_id AND fab_id=prod_fab_id ORDER BY RAND()'; // LIMIT ' . $cuantos; $this->result = mysql_query($query, $conn); $this->numOfertas = mysql_num_rows($this->result); } } function getNum() { return $this->numOfertas; } function getNextOferta(){ $oferta = ''; if($this->contador < $this->numOfertas) { $row = mysql_fetch_array($this->result); $this->contador ++; if(file_exists('_prds/' . $row['prod_id'] . ($this->curTipo != 2 ? '_168.jpg' : '_247.jpg'))) { $oferta = array ( 'marca' => $row['fab_nombre'], 'marca_id' => $row['fab_id'], 'id_modelo' => $row['prod_id'], 'modelo' => $row['prod_modelo'], 'precio' => $row['prod_precio'], 'texto' => $row['prod_descripcion'], 'catid' => $row['prod_categoria_id'], 'producto' => componProducto($row['cat_nombre'], $row['cat_seccion'])); } else { $oferta = $this->getNextOferta(); } } return $oferta; // es un array } } class shoopOcasion{ var $result; var $cuantas; var $numOfertas; var $curTipo; function shoopOcasionSurtiditos($cuantos) { // esta es mi entrada en la clase, aqu? inicializo las globales. $this->numOfertas = 0; $this->contador = 0; $this->result = false; $this->curTipo = $tipo; $conn = db_connect(); if($conn) { $query = 'SELECT ocasion_categoria AS CATEGORIA, ocasion_nombre AS NOMBRE, ocasion_estado AS ESTADO, ocasion_pvp AS PVP, ocasion_precio AS PRECIO, ocasion_descripcion AS TEXTO FROM shoop_ocasion WHERE ocasion_unidades > 0 ORDER BY RAND() LIMIT ' . $cuantos; $this->result = mysql_query($query, $conn); $this->numOfertas = mysql_num_rows($this->result); } } function getNum() { return $this->numOfertas; } function getNext(){ return mysql_fetch_array($this->result); } } ?>