59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
// este script devuelve N banners del tipo solicitado
|
|||
|
|
|
|||
|
|
// esta clase devuelve un trozo de html con la url ya creada
|
|||
|
|
|
|||
|
|
|
|||
|
|
class shoopBanners{
|
|||
|
|
|
|||
|
|
var $result;
|
|||
|
|
var $cuantas;
|
|||
|
|
var $numBanners;
|
|||
|
|
var $conn;
|
|||
|
|
|
|||
|
|
function shoopBanners($cuantos, $tipo = 1){
|
|||
|
|
// esta es mi entrada en la clase, aqu<71> inicializo las globales.
|
|||
|
|
$this->numBanners = 0;
|
|||
|
|
$this->contador = 0;
|
|||
|
|
$this->result = false;
|
|||
|
|
$buscar = '';
|
|||
|
|
|
|||
|
|
$this->conn = db_connect();
|
|||
|
|
if($this->conn) {
|
|||
|
|
$query = 'SELECT banner_id, banner_texto, banner_file, banner_url, banner_inserts FROM bania_banners WHERE banner_tipo=' . $tipo . ' ORDER BY RAND() LIMIT ' . $cuantos;
|
|||
|
|
$this->result = mysql_query($query, $this->conn);
|
|||
|
|
if($this->result) {
|
|||
|
|
$this->numBanners = mysql_num_rows($this->result);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function getNum() {
|
|||
|
|
return $this->numBanners;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// aqui no devuelvo una matriz, sino simplemente un trozo de html que dibuja mi imagen y
|
|||
|
|
// si fuera menester el enlace correspondiente.
|
|||
|
|
function getNextBanner(){
|
|||
|
|
$oferta = '';
|
|||
|
|
$hasURL = 0;
|
|||
|
|
|
|||
|
|
if($this->contador < $this->numBanners) {
|
|||
|
|
$row = mysql_fetch_array($this->result);
|
|||
|
|
$this->contador ++;
|
|||
|
|
if(strlen($row['banner_url'])) {
|
|||
|
|
$hasURL = 1;
|
|||
|
|
}
|
|||
|
|
$banner = ($hasURL ? '<a href="http://' . $row['banner_url'] . '" target="_blank">' : '') . '<img src="_bann/' . $row['banner_file'] . '" alt="' . $row['banner_texto'] . '" border="0">' . ($hasURL ? '</a>' : '') ;
|
|||
|
|
// sumo una insercion en el banner correspondiente.
|
|||
|
|
if($this->conn) {
|
|||
|
|
$nuInserts = $row['banner_inserts'] + 1;
|
|||
|
|
$query = 'UPDATE bania_banners SET banner_inserts="' . $nuInserts . '" WHERE banner_id=' . $row['banner_id'];
|
|||
|
|
mysql_query($query, $this->conn);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return $banner;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
?>
|