WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A what happened on this day class
Categories : PHP, PHP Classes, Databases, MySQL Click here to Update Your Picture
Khair-ed Din Husseini
Date : Mar 26th 2005
Grade : 3 of 5 (graded 5 times)
Viewed : 4567
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Khair-ed Din Husseini
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

a nice and easy way to implement class for "What happened today?" for websites.
Note that if the class cannot find an event on the current date, it will take out the last occurence of an event.

<?php

/**
* --
* -- Table structure for table `events`
* --
*
* CREATE TABLE `events`
* (
*      `id` int(8) NOT NULL auto_increment,
*      `date` date NOT NULL default '0000-01-01',
*      `event` text NOT NULL,
*      PRIMARY KEY  (`id`)
* );
**/


class eventClass
{
    var
$day;
    var
$table = "events";
    var
$columnText = "event";
    var
$columnID = "id";
    var
$columnDate = "date";
    var
$myEventArray = array
    (
       
"eventID" => array(),
       
"eventText" => array(),
       
"eventDate" => array(),
    );
   
/**
    * @return Array/Boolean
    * @desc Returns the events array from database. Return false if failed.
    */
     
function get()
    {
       
$this->checkDate(date('d'));
        return
$this->myEventArray;
    }
   
/**
    * @return Boolean
    * @param String $text
    * @param Integer $month
    * @param Integer $day
    * @param Integer $year
    * @desc Inserts a new event into database. Returns false if failed.
    */
     
function set($text, $month, $day, $year)
    {
       
$date = $year . "-" . $month . "-" . $day;
       
$query = "insert into " . $this->table . "(" . $this->columnText . ", " . $this->columnDate . ") values('" . $text . "', '" . $date . "')";
       
$result = mysql_query($query);
        if(
$result)
        {
            if(
mysql_affected_rows())
                return
true;
            else
                return
false;
        }
        else
            return
false;
    }
   
/* FUNCTIONS*/
    /**
    * @return Boolean
    * @param Integer $id
    * @desc Deletes event from database
    */
     
function delete($id)
    {
       
$query = "delete from " . $this->table . " where " . $this->columnID . "=" . $id;
       
$result = mysql_query($query);
        if(
$result)
        {
            if(
mysql_affected_rows())
                return
true;
            else
                return
false;
        }
        else
            return
false;
    }
   
   
/**
    * @return Boolean
    * @param Integer $id
    * @param String $text
    * @desc Updates selected row in database. Return false if failed.
    */
     
function update($id, $text)
    {
       
$query = updateQuery($this->table, $this->columnText, $text, $this->columnID, $id);
       
$result = mysql_query($query);
        if(
$result)
        {
            if(
mysql_affected_rows())
                return
true;
            else
                return
false;
        }
        else
            return
false;
    }
   
   
/**
    * @return Boolean
    * @param Integer $month
    * @desc Checks event data in database and sets an array of the last recent month and day match. Returns false if failed.
    */
     
function checkDate($month)
    {
       
$this->day = date('d');
       
$result = $this->queryMonth($month);
        if(
$result)
        {
            if(
mysql_fetch_array($result))
            {
               
$this->checkDay($month);
               
$this->getArray($month, $this->day);
                return
true;
            }
            else
            {
                if(
$month == 1)
                   
$this->checkDate(12);
                else
                {   
                   
$month--;
                   
$this->checkDate($month);
                }               
            }
        }
        else
            return
false;
    }
   
/**
    * @return Boolean
    * @param Integer $month
    * @desc Checks last recent day in event dates
    */
     
function checkDay($month)
    {
       
$result = $this->queryDay($month, $this->day);
        if(
$result)
        {
            if(
mysql_fetch_array($result))
                return
true;
            else
            {
                if(
$this->day == 1)
                {
                   
$this->day = 31;
                   
$this->checkDay($month);
                }
                else
                {
                   
$this->day--;
                   
$this->checkDay($month);
                }
            }
        }
        else
            return
false;
    }
   
/**
    * @return Boolean
    * @param integer $month
    * @param integer $day
    * @desc Sets the event Array. Returns false if failes.
    */
     
function getArray($month, $day)
    {
       
$query = "select * from " . $this->table . " where " . $this->columnDate . " like '%-%" . $month . "-%" . $day . "'";
       
$result = mysql_query($query);
        if(
$result)
        {
            if(
$myrow = mysql_fetch_array($result))
            {
               
               
$index = 0;
                do
                {
                   
$this->myEventArray["eventID"][$index] = $myrow[$this->columnID];
                   
$this->myEventArray["eventText"][$index] = $myrow[$this->columnText];
                   
$this->myEventArray["eventDate"][$index] = $myrow[$this->columnDate];
                   
$index++;
                }while(
$myrow = mysql_fetch_array($result));
                return
true;
            }
            else
                return
false;
        }
        else
            return
false;
    }
   
/**
    * @return Recource/Boolean
    * @param Integer $month
    * @param Integer $day
    * @desc Gives apropriate recource ID. Returns false if failed
    */
     
function queryDay($month, $day)
    {
       
$query = "select DATE_FORMAT(date, '%d') as day from " . $this->table . " where " . $this->columnDate . " like '%-%" . $month . "-%" . $day . "'";
       
$result = mysql_query($query);
        if(
$result)
            return
$result;
        else
            return
false;
    }   
   
/**
    * @return Recource/Boolean
    * @param Integer $month
    * @desc Gives apropriate recource ID. Returns false if failed
    */
     
function queryMonth($month)
    {
       
$query = "select " . $this->columnDate . " from " . $this->table . " where " . $this->columnDate . " like '%-%" . $month . "-%'";
       
$result = mysql_query($query);
        if(
$result)
            return
$result;
        else
            return
false;
    }
}
?>



[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL