--
-- Table structure for table `posts`
--
CREATE TABLE `posts` (
`id` int(11) NOT NULL,
`title` varchar(100) NOT NULL,
`content` text NOT NULL,
`link` varchar(255) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `posts`
--
INSERT INTO `posts` (`id`, `title`, `content`, `link`, `timestamp`) VALUES
(1, 'Yes, except the Dave Matthews Band doesn\'t rock.', 'The alien mothership is in orbit here. If we can hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate. If rubbin\' frozen dirt in your crotch is wrong, hey I don\'t wanna be right.', 'link-1', '2021-03-21 05:41:54'),
(2, 'Saving the world with meals on wheels.', 'You know how I sometimes have really brilliant ideas? Heh-haa! Super squeaky bum time! I\'m the Doctor. Well, they call me the Doctor. I don\'t know why. I call me the Doctor too. I still don\'t know why.', 'link-2', '2021-03-21 05:42:02'),
(3, 'Tell him time is of the essence.', 'This man is a knight in shining armor. Watching ice melt. This is fun. Tell him time is of the essence. This man is a knight in shining armor. You look perfect. He taught me a code. To survive.', 'link-3', '2021-03-21 05:42:08'),
(4, 'What is AngularJS', 'AngularJS is a JavaScript MVC framework developed by Google that lets you build well structured, easily testable, declarative and maintainable front-end applications which provides solutions to standard infrastructure concerns.', 'link-5', '2021-03-20 16:00:00'),
(5, 'What is MongoDB', 'It is a quick tutorial on MongoDB and how you can install it on your Windows OS. We will also learn some basic commands in MongoDB for example, creating and dropping a Database, Creation of a collection and some more operations related to the collection.', 'link-6', '2021-03-21 16:00:00'),
(6, 'Python Flask Load content Dynamically in Bootstrap Modal with Jquery AJAX and Mysqldb', 'Python Flask Load content Dynamically in Bootstrap Modal with Jquery AJAX and Mysqldb', 'link-6', '2021-03-20 16:00:00'),
(7, 'AutoComplete Textbox with Image using jQuery Ajax PHP Mysql and JqueryUI', 'AutoComplete Textbox with Image using jQuery Ajax PHP Mysql and JqueryUI', 'link-7', '2021-03-14 16:00:00'),
(8, 'PHP Mysql Registration Form Validation using jqBootstrapValidation with Jquery Ajax', 'PHP Mysql Registration Form Validation using jqBootstrapValidation with Jquery Ajax', 'link-8', '2021-03-20 16:00:00'),
(9, 'Python Flask Registration Form Validation using jqBootstrapValidation with Jquery Ajax and Mysql', 'Python Flask Registration Form Validation using jqBootstrapValidation with Jquery Ajax and Mysql', 'link-9', '2021-03-19 16:00:00'),
(10, 'Displaying Popups data on mouse hover using Jquery Ajax and PHP Mysql database', 'Displaying Popups data on mouse hover using Jquery Ajax and PHP Mysql database', 'link-10', '2021-03-15 16:00:00'),
(11, 'Displaying Popups data on mouse hover using Jquery Ajax and Python Flask Mysql database', 'Displaying Popups data on mouse hover using Jquery Ajax and Python Flask Mysql database', 'link-11', '2021-03-14 16:00:00');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `posts`
--
ALTER TABLE `posts`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `posts`
--
ALTER TABLE `posts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;
//index.php <!doctype html> <html> <head> <title>Load more data using jQuery,AJAX, and PHP</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <style> .container{ width: 55%; margin: 0 auto; border: 0px solid black; padding: 10px 0px; } .post{ width: 97%; min-height: 200px; padding: 5px; border: 1px solid gray; margin-bottom: 15px; } .post h1{ letter-spacing: 1px; font-weight: normal; font-family: sans-serif; } .post p{ letter-spacing: 1px; text-overflow: ellipsis; line-height: 25px; } .load-more{ width: 99%; background: #15a9ce; text-align: center; color: white; padding: 10px 0px; font-family: sans-serif; } .load-more:hover{ cursor: pointer; } .more{ color: blue; text-decoration: none; letter-spacing: 1px; font-size: 16px; } </style> </head> <body> <div class="container"> <h2 align="center">Load more data using jQuery AJAX and PHP Mysql</a></h2> <br /> <?php include "config.php"; $rowperpage = 3; // counting total number of posts $allcount_query = "SELECT count(*) as allcount FROM posts"; $allcount_result = mysqli_query($con,$allcount_query); $allcount_fetch = mysqli_fetch_array($allcount_result); $allcount = $allcount_fetch['allcount']; // select first 3 posts $query = "select * from posts order by id asc limit 0,$rowperpage "; $result = mysqli_query($con,$query); while($row = mysqli_fetch_array($result)){ $id = $row['id']; $title = $row['title']; $content = $row['content']; $shortcontent = substr($content, 0, 160)."..."; $link = $row['link']; ?> <div class="post" id="post_<?php echo $id; ?>"> <h1><?php echo $title; ?></h1> <p><?php echo $shortcontent; ?></p> <a href="<?php echo $link; ?>" class="more" target="_blank">More</a> </div> <?php } ?> <h1 class="load-more">Load More</h1> <input type="hidden" id="row" value="0"> <input type="hidden" id="all" value="<?php echo $allcount; ?>"> </div> <script> $(document).ready(function(){ $('.load-more').click(function(){ var row = Number($('#row').val()); var allcount = Number($('#all').val()); row = row + 3; if(row <= allcount){ $("#row").val(row); $.ajax({ url: 'getData.php', type: 'post', data: {row:row}, beforeSend:function(){ $(".load-more").text("Loading..."); }, success: function(response){ setTimeout(function() { $(".post:last").after(response).show().fadeIn("slow"); var rowno = row + 3; if(rowno > allcount){ $('.load-more').text("Hide"); $('.load-more').css("background","darkorchid"); }else{ $(".load-more").text("Load more"); } }, 2000); } }); }else{ $('.load-more').text("Loading..."); setTimeout(function() { $('.post:nth-child(3)').nextAll('.post').remove().fadeIn("slow"); $("#row").val(0); $('.load-more').text("Load more"); $('.load-more').css("background","#15a9ce"); }, 2000); } }); }); </script> </body> </html>config.php
//config.php <?php $host = "localhost"; $user = "root"; $password = ""; $dbname = "testingdb"; $con = mysqli_connect($host, $user, $password,$dbname); if (!$con) { die("Connection failed: " . mysqli_connect_error()); }getData.php
//getData.php <?php include 'config.php'; $row = $_POST['row']; $rowperpage = 3; $query = 'SELECT * FROM posts limit '.$row.','.$rowperpage; $result = mysqli_query($con,$query); $html = ''; while($row = mysqli_fetch_array($result)){ $id = $row['id']; $title = $row['title']; $content = $row['content']; $shortcontent = substr($content, 0, 160)."..."; $link = $row['link']; $html .= '<div id="post_'.$id.'" class="post">'; $html .= '<h1>'.$title.'</h1>'; $html .= '<p>'.$shortcontent.'</p>'; $html .= '<a href="'.$link.'" class="more" target="_blank">More</a>'; $html .= '</div>'; } echo $html;