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

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`)
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);
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`)

Step 2. PHP
Now, please create empty index.php file and put next code:
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);
08 require_once(‘classes/CMySQL.php’); // include service classes to work with database and comments
09 require_once(‘classes/CMyComments.php’);
11 if ($_POST[‘action’] == ‘accept_comment’) {
12 echo $GLOBALS[‘MyComments’]->acceptComment();
13 exit;
14 }
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 .= ‘<div class=”photo”><img src=”images/thumb_’.$aItemInfo[‘filename’].'” id=”‘.$aItemInfo[‘id’].'” /><p>’.$aItemInfo[‘title’].’ item</p><i>’.$aItemInfo[‘description’].'</i></div>’;
21 }
23 ?>

Download Files Here


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

  1. Hey I know this is off topic but I was wondering if you knew of any widgets
    I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.


  2. I’m very happy to find this page. I need to to thank you for ones time for this wonderful read!! I definitely really liked every little bit of it and i also have you bookmarked to check out new things in your blog.


  3. I like the helpful information you provide in
    your articles. I’ll bookmark your weblog and check again here frequently. I’m fairly sure
    I’ll learn many new stuff right right here! Best of luck for the next!


  4. Hello there I am so happy I found your website, I really found
    you by accident, while I was browsing on Aol for something else, Regardless I am here now and would
    just like to say thanks for a tremendous post and a all round entertaining blog (I also
    love the theme/design), I don’t have time to look over it all
    at the moment but I have saved it and also added in your RSS feeds,
    so when I have time I will be back to read much more, Please do keep up the superb jo.


  5. I used to be recommended this web site by my cousin.

    I’m now not positive whether this publish is written through him as nobody else recognize such special approximately my trouble. You’re amazing!
    Thank you!


  6. It’s very trouble-free to find out any matter on net as compared to books, as I found this article at this web site.


  7. Write more, thats all I have to say. Literally, it seems as though you
    relied on the video to make your point. You clearly know what youre talking about,
    why throw away your intelligence on just posting videos to your weblog when
    you could be giving us something enlightening to read?


  8. Heya are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get started
    and set up my own. Do you need any html coding expertise to
    make your own blog? Any help would be greatly appreciated!


  9. Pretty nice post. I just stumbled upon your blog and wished to say that I have truly enjoyed browsing
    your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!


  10. I savor, cause I found exactly what I used to be looking for. You have ended my 4 day lengthy hunt! God Bless you
    man. Have a nice day. Bye


  11. Thanks very interesting blog!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s