BLAG Ramblings of a crazy old fool

25Nov/070

Christmas List

Click here for my 2007 Christmas List

So here is my Christmas present to you, intarwebs: The source! This is PHP/MySQL and can be easily included in any PHP page. Get your list started early (late?) this year with new code!

<?php

  //
  // christmaslist.php
  // Chistmas List script for weblog
  //
  // Author: Joshua Worden, IWM Entertainment
  // Released Nov. 2007 under GPL
  //
  // Usage: Designed to be included on a page.

  /*
     --
     -- Table structure for table `christmaslist`
     -- 

      CREATE TABLE `christmaslist` (
       `id` int(11) NOT NULL auto_increment,
       `image` text NOT NULL,
       `title` text NOT NULL,
       `description` text NOT NULL,
       `price` float NOT NULL default '0',
       `date` datetime NOT NULL default '0000-00-00 00:00:00',
    PRIMARY KEY  (`id`),
    FULLTEXT KEY `description` (`description`)
    ) TYPE=MyISAM AUTO_INCREMENT=5 ;

    --
    -- End table structure
    --
  */

  // Definitions 

  $_site['sql-host']      = ""; // MySQL Host (localhost)
  $_site['sql-user']      = ""; // MySQL Username
  $_site['sql-pass']      = ""; // MySQL Password
  $_site['sql-data']      = ""; // MySQL Database

  // Functions

  function DisplayItems($B_SORTED, $T_SORTMODE) {
    if($B_SORTED) { $Q_SQL1 = mysql_query("SELECT * FROM christmaslist ORDER BY ".$T_SORTMODE." ASC;");}
    else          { $Q_SQL1 = mysql_query("SELECT * FROM christmaslist ORDER BY date ASC;"); }

    echo "<div style=\"width:100%; text-align:center; margin:0 auto;\">\r\n";
    echo "<div style=\"width:100%; clear:both;\">\r\n";
    echo "<div style=\"width:20%;float:left;position:relative;\"><a href=\"?sort=image\"><b>Category</b></a></div>";  // [Image]
    echo "<div style=\"width:20%;float:left;position:relative;\"><a href=\"?sort=title\"><b>Title</b></a></div>";     // Title
    echo "<div style=\"width:20%;float:left;position:relative;\"><b>Description</b></div>";                           // [Description]
    echo "<div style=\"width:20%;float:left;position:relative;\"><a href=\"?sort=price\"><b>Price</b></a></div>";     // Price
    echo "<div style=\"width:20%;float:left;position:relative;\"><a href=\"?sort=date\"><b>Date Added</b></a></div>"; // Date Added
    echo "</div>";
    while($T_SQLRESULT=mysql_fetch_array($Q_SQL1)) {
      echo "<div style=\"width:100%; clear:both;\">\r\n";
      echo "<div style=\"width:20%;height:100px;float:left;position:relative;\"><img src=/images/thumbs/".$T_SQLRESULT['image']." /></div>";
      echo "<div style=\"width:20%;float:left;position:relative;\">".$T_SQLRESULT['title']."</div>";
      echo "<div style=\"width:20%;float:left;position:relative;\">".$T_SQLRESULT['description']."</div>";
      echo "<div style=\"width:20%;float:left;position:relative;\">$".$T_SQLRESULT['price']."</div>";
      echo "<div style=\"width:20%;float:left;position:relative;\">".$T_SQLRESULT['date']."</div>";
      echo "</div>";
      }
    echo "<div style=\"width:100%; clear:both;\"> </div>\r\n";
    echo "</div>\r\n";
    }

  function Error($T_ERROR) {
    // Show error
    echo "<div style=\"width:400px; height:150px; clear:both; background:#FF0000;\">\r\n";
    echo "\t<h4><font color=#FFFFFF>MySQL Error:</font></h4>\r\n" . $T_ERROR . "\r\n";
    echo "</div>\r\n";
    die;
    }

  // Connect to MySQL

  $B_SQLCONN = @mysql_connect($_site['sql-host'],$_site['sql-user'],$_site['sql-pass']);
  $B_SQLDATA = @mysql_select_db($_site['sql-data']);
  if(!$B_SQLCONN || !$B_SQLDATA){Error(mysql_error());}

  // Check for sort mode

  if(isset($_GET['sort'])) { DisplayItems(TRUE, $_GET['sort']); }
  else { DisplayItems(FALSE,"date"); }

?>
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

 

No trackbacks yet.