Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Sebastián http://www.envero.org

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Loop de X elementos por fila

// Genera una estructura que va colocando un resultset en filas de X elementos.

<?php

// Catálogos
$catalogos_query = 'SELECT catalogos.* FROM catalogos WHERE catalogos.estado = 1 ORDER BY catalogos.id_catalogo DESC';
$catalogos_rs = mysql_query( $catalogos_query );
$catalogos_num = mysql_num_rows( $catalogos_rs );

// inicia looper
$elem_count = 0;
$elem_total_count = 0;
$elem_per_row = 6; // Configurar esto!
// bucle entre todas los elementos a mostrar
while( $row = mysql_fetch_assoc( $catalogos_rs ) ) :
	$elem_count++;
	$elem_total_count++;
?>

	<?php if ( $elem_count == 1 ) : // si es el primer elemento de la fila.... ?>

	<div class="catalogoRow">

	<?php endif; ?>	

	<?php if ( $elem_count == $elem_per_row ) : // si es el último elemento de la fila...
		$class = "catalogoContainer ultimo";
	else:
		$class = "catalogoContainer";
	endif; ?>

		<div class="<?php echo $class ?>">

			<div class="catalogoImagen">
				<a target="_blank" href="/arxius/catalogos/<?php echo $row['archivo']; ?>"><img src="../arxius/catalogos/<?php echo $row['imagen']; ?>" alt="<?php echo $row['titulo_'.$idioma]; ?>" border="0" /></a>
			</div>
			<div class="catalogoTitulo">
				<p><?php echo $row['titulo_'.$idioma]; ?></p>
			</div>

		</div><!-- end .container -->

	<?php if ( $elem_count == $elem_per_row || $catalogos_num == $elem_total_count ) : // elem_db_total es el total de reg. a mostrar de la bbdd ?>
		<div class="clear"></div>

	</div><!-- end .row -->

	<?php $elem_count = 0; endif; ?>

<?php endwhile; ?>

Devuelve el Referer limpio

// Limpia y devuelve el REFERER

	function getReferer(){
		// limpia el referer 
		$ref = $_SERVER['HTTP_REFERER'];
		$web = str_replace(array('http://','www.'),'',$ref);
		$web = substr($web,0,strpos ($web, '/'));
		if(!empty($web)):
			// retorna el referer limpio
			return $web;
		else:
			// sin referer
			return 'jane.es';
		endif;
	}

recupera datos del visitante

	function getLocation( $ip ) {
		
		static $location = array();
		
		if( !isset( $location[$ip] ) ) {
			$url = "http://www.hostip.info/api/get.html?ip=" . $ip . "&position=true&raandom=" . rand(0,500);
			/* cURL */
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$data = curl_exec($ch);

			if ( curl_errno( $ch ) ) {
				print "Error: ".curl_error($ch);
			} else {
				curl_close($ch);
				$lines = split ("\n", $data);
				foreach($lines as $l):
					$prop = split(':',$l);
					$location[$ip][trim($prop[0])] = addslashes(trim($prop[1]));
				endforeach;
		   }
			
		}
		return $location[$ip];
	}
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS