BLAG Ramblings of a crazy old fool

18Nov/070

[PHP|MySQL] Image Gallery

Short and not-so-sweet, an Image Gallery! I needed something for the site, and 4images just seemed too bloated for what I needed. And, being lazy, I didn't really wanna go and look for one that badly. So I wrote one. I'll be testing this later tonight, I'll post any fixes as they come up.

<?php

  // images/index.php
  // MySQL/PHP Image Gallery
  //
  // Author: Joshua Worden, IWM Entertainment
  // Released Nov. 2007 under GPL
  //
  // Usage: Designed to be used as index file in a subdirectory, or to point to a subdirectory

  // Definitions 

  $_site['sql-host']      = "";
  $_site['sql-user']      = "";
  $_site['sql-pass']      = "";
  $_site['sql-data']      = "";
  $_site['sql-table1']    = "";
  $_site['sql-table2']    = "";

  $_sql['select_gallerylist'] = "SELECT id,title from $_site['sql-table1']";
  $_sql['select_gallery']     = "SELECT * FROM $_site['sql-table2'] WHERE gallery=$id";
  $_sql['select_image']       = "SELECT * FROM $_site['sql-table2'] WHERE id=$id LIMIT 1";

  // Functions

  function Display_GalleryList() {
    echo "<div class=galleryblock>";
    echo "<div class=title>My Galleries</div>";
    while($sqlresult = mysql_fetch_array(mysql_query($_sql['select_gallerylist']))) {
      echo "<div class=thumb><a href=?Display=Gallery&id=$sqlresult['id']><img src=gallery.jpg alt=\"$sqlresult['title']\" /><b>$sqlresult['title']</b></div>";
      }
    echo "</div>";
    }

  function Display_Gallery($id) {
    echo "<div></div>";
    }

  function Display_Image($id) {
    echo "<div class=imageblock>";
    $count=1;
    while($sqlresult=mysql_fetch_array(mysql_query($_sql['select_gallery']))) {
      if($count\5=0) { echo "<br />"; }
      echo "<div class=title>$sqlresult['title']</div>";
      echo "<img src=$sqlresult['filename'] class=centered alt=$sqlresult['title'] /><br />";
      echo "<div class=description>$sqlresult['description']</div>";
      $count++;
      }
    echo "</div>";
    }

  // Connect to MySQL

  @mysql_connect($_site['sql-host'],$_site['sql-user'],$_site['sql-pass']);
  @mysql_select_db($_site['sql-data']);

  // Check to see what we're displaying

  if(isset($_GET['Display'])) {         // Check for correct info
    if($_GET['Display'] == "Image") {   // If displaying an image
      Display_Image($_GET['id']);
      }
    elseif($_GET['Display'] == "Gallery") {
      Display_Gallery($_GET['id']);
      }
    else { Display_GalleryList(); }
    }
  else { Display_GalleryList(); }

  ?>
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

 

No trackbacks yet.