jQuery ,MYSQL and PHP to create : Facebook like photo gallery with comments

Sharing is caring!

Have you considered own facebook-style photograph gallry framework with remarks? I suppose – yes. Today I made up my psyche to plan it for you. Fundamental thought – when we click at pictures – they popup (ajax) with greater picture at the left and remarks area at the right. All pictures are in the database (mysql). Furthermore, obviously, we will utilize Php to realize our effect. Additionally, our remark framework will anticipate tolerating more than 1 remark for every 10 mins (to dodge spam).

Step 1. SQL
For our gallery I prepared two SQL tables: first table keeps records of our images. It contains several fields: title, filename, description, time of adding and comments count. Another table keeps comments. So, execute next SQL instructions:

01 CREATE TABLE IF NOT EXISTS `s281_photos` (
02 `id` int(10) unsigned NOT NULL auto_increment,
03 `title` varchar(255) default ”,
04 `filename` varchar(255) default ”,
05 `description` text NOT NULL,
06 `when` int(11) NOT NULL default ‘0’,
07 `comments_count` int(11) NOT NULL default ‘0’,
08 PRIMARY KEY (`id`)
09 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
10
11 INSERT INTO `s281_photos` (`title`, `filename`, `description`, `when`) VALUES
12 (‘Item #1’, ‘photo1.jpg’, ‘Description of Item #1’, UNIX_TIMESTAMP()),
13 (‘Item #2’, ‘photo2.jpg’, ‘Description of Item #2’, UNIX_TIMESTAMP()+1),
14 (‘Item #3’, ‘photo3.jpg’, ‘Description of Item #3’, UNIX_TIMESTAMP()+2),
15 (‘Item #4’, ‘photo4.jpg’, ‘Description of Item #4’, UNIX_TIMESTAMP()+3),
16 (‘Item #5’, ‘photo5.jpg’, ‘Description of Item #5’, UNIX_TIMESTAMP()+4),
17 (‘Item #6’, ‘photo6.jpg’, ‘Description of Item #6’, UNIX_TIMESTAMP()+5),
18 (‘Item #7’, ‘photo7.jpg’, ‘Description of Item #7’, UNIX_TIMESTAMP()+6),
19 (‘Item #8’, ‘photo8.jpg’, ‘Description of Item #8’, UNIX_TIMESTAMP()+7),
20 (‘Item #9’, ‘photo9.jpg’, ‘Description of Item #9’, UNIX_TIMESTAMP()+8),
21 (‘Item #10’, ‘photo10.jpg’, ‘Description of Item #10’, UNIX_TIMESTAMP()+9);
22
23 CREATE TABLE IF NOT EXISTS `s281_items_cmts` (
24 `c_id` int(11) NOT NULL AUTO_INCREMENT ,
25 `c_item_id` int(12) NOT NULL default ‘0’,
26 `c_ip` varchar(20) default NULL,
27 `c_name` varchar(64) default ”,
28 `c_text` text NOT NULL ,
29 `c_when` int(11) NOT NULL default ‘0’,
30 PRIMARY KEY (`c_id`),
31 KEY `c_item_id` (`c_item_id`)
32 ) ENGINE=MYISAM DEFAULT CHARSET=utf8;

Step 2. PHP
Now, please create empty index.php file and put next code:
index.php
01 <?php
02 // disable warnings
03 if (version_compare(phpversion(), “5.3.0”, “>=”) == 1)
04 error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
05 else
06 error_reporting(E_ALL & ~E_NOTICE);
07
08 require_once(‘classes/CMySQL.php’); // include service classes to work with database and comments
09 require_once(‘classes/CMyComments.php’);
10
11 if ($_POST[‘action’] == ‘accept_comment’) {
12 echo $GLOBALS[‘MyComments’]->acceptComment();
13 exit;
14 }
15
16 // prepare a list with photos
17 $sPhotos = ”;
18 $aItems = $GLOBALS[‘MySQL’]->getAll(“SELECT * FROM `s281_photos` ORDER by `when` ASC”); // get photos info
19 foreach ($aItems as $i => $aItemInfo) {
20 $sPhotos .= ‘

‘.$aItemInfo[‘title’].’ item

‘.$aItemInfo[‘description’].’

‘;
21 }
22
23 ?>

Download Files Here

12 thoughts on “jQuery ,MYSQL and PHP to create : Facebook like photo gallery with comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Got Project on mind? Let's ConnectContact Us

Secured By miniOrange