miércoles, 26 de noviembre de 2008

Paginate, paginate, paginate


Paginate your queries, be happy, be hippie...


<?

$docs=10;

if (empty($_GET[pg])) { $_GET[pg]=1; }
if ($_GET[pg] < 1) { $pg=0; } else { $pg=$_GET[pg]-1; }

$ini=$pg*$docs;
$fin=$ini+$docs;

$sel_docs="SELECT id_doc,titulo FROM docs ORDER BY id_doc DESC ";
if (isset($_GET[query]) && $_GET[query]!='') {
$sel_docs.="WHERE titulo LIKE '%".$_GET[query]."%'";
}
$sel_docs.=" LIMIT $ini,$fin";

$qdocs=mysql_query($sel_docs);

while ($rdocs=mysql_fetch_array($qdocs)) {
/// do your stuff
}


echo "<p align='center'>";
/////////////
$sql_count="SELECT id_doc FROM docs ";
if (isset($_GET[query]) && $_GET[query]!='') { $sel_docs.="WHERE titulo LIKE '%".$_GET[query]."%'"; }
$q_count=mysql_query($sql_count);
$num=mysql_num_rows($q_count); // cuántos artículos hay

$anterior=$_GET[pg]-1;
$siguiente=$_GET[pg]+1;
$pg_max=ceil($num/$docs); // número máximo de páginas

$num_list=24; // número de páginas listadas -- de 0 a $num_list

if ($pg!=0) {
echo "<a href='index.php?p=".$_GET[p]."&pg=".$anterior."&query=".$_GET[query]."'>Anterior</a> ";
}

/// define desde que página inicia la numeración
if (empty($_GET[query])) {
if ($_GET[pg]<=10) {
$start_at=1;
} else if ($_GET[pg]>($pg_max-$num_list)) {
$start_at=$pg_max-$num_list;
} else {
$start_at=$_GET[pg]-10;
}
}

$pg_tmp=$start_at;
if ($num_list>$pg_max) { $num_list=$pg_max; }

//////////// paginado
for ($i = 0; $i < $num_list; $i++) {
if ($pg_tmp==$_GET[pg]) { echo "<b>$pg_tmp</b> | ";
} else {
echo "<a href='index.php?p=".$_GET[p]."&pg=".$pg_tmp."&query=".$_GET[query]."'>".$pg_tmp."</a> | "; }
$pg_tmp++;
}

if ($_GET[pg]!=$pg_max) {
echo "<a href='index.php?p=".$_GET[p]."&pg=".$siguiente."&query=".$_GET[query]."'>Siguiente</a> ";
}

echo "</p>";


?>


sorry for the spanglish...

sábado, 22 de noviembre de 2008

Great PHP image resize code 4 thumbnails


This works just great!! check it out. Thumbs are created from those very images displayed with lightbox!

This will resize your image but it won't stretch it and it'll keep right proportions. Basically this crops your image to fit the best.

function createThumb($source,$dest) {
$thumb_size = 230; // square thumbs
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];

// you might comment this to make regular thumbs and add a thumb width var. keep this for square thumbs
if($width> $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} else if ($height> $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}

$new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
$im = imagecreatefromjpeg($source);
imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
imagejpeg($new_im,$dest,100);
}

miércoles, 12 de noviembre de 2008

Lost in translation

Once I heard on the radio that a movie wich starts with a close up of Scarlett Johanson's butt can't be bad at all... and as far as I know it's true. Here's an example.


Well... I have a clue of where translation may had got lost.

Happiness is real only when shared

As friendship is a human need just like happiness, these may not coexist sepparately... we are social animals...

domingo, 2 de noviembre de 2008

I luv zombies


The Walking Dead is centered around a small-town police officer from Cynthiana, Kentucky, his family, and a number of other survivors who have banded together in order to survive after the world is overrun with zombies. As the series progresses, the characters become more developed, and their personalities shift under the stress of a zombie apocalypse. Fighting growing despair — and occasionally each other — the group searches for a secure location which they can finally call home...

  • Find out more at Wikipedia
  • Zomics. Check out this site where you'll find more info about many comic titles about zombies... I think this is mostly in spanish...
  • Check out mininova results.
  • Links in this site seem to be working... bdcomics.bdgamers