PHP Display Limited text from Database using PHP Read More Link
PHP MySQL Display Limited Words with Read More Link |
Hi Guys in This tutorial we will Learn how to Display Limit Length Text form Database using PHP.
It's Very easy,simple and Beginners friendly.
Database and Files Structure:
PHP MySQL Display Limited Words with Read More Link |
Database Name: tutorial
Table Name: test
use the below SQL Commands to Create test table.
CREATE TABLE IF NOT EXISTS `topic` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(150) NOT NULL, `description` longtext NOT NULL, `creator` varchar(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
To Insert data use the Below SQL Commands.
INSERT INTO `topic` (`id`, `title`, `description`, `creator`) VALUES (1, 'Types of Hosting with Explanation', 'The three types of hosting that are generally available are: Shared, Dedicated, and Virtual Private Servers (VPS).\r\n\r\nThese three options combine to cover small, medium, and large websites. Usually, a website size can be determined by the number of monthly visitors. Don’t be afraid to fall in the small section, as 99.9 percent of websites are considered small and it is significantly cheaper!\r\n1. Shared Hosting
\r\n\r\nShared hosting is by far the most common option for small businesses, individuals, and even some popular websites. Shared hosting is many websites hosting on a single server (remember server just means computer). The advantage to using shared hosting is it makes it extremely cheap because of the shared resources (see pricing).\r\n\r\nShared hosts can handle websites that run WordPress, Joomla, or others and also make this process very easy to set up. A shared host can handle up to 30,000 visitors per month, which covers most websites. If you are just getting started with hosting, you should take a close look at shared hosting for its value and performance.\r\n\r\n2. Dedicated Hosting
\r\n\r\nDedicated hosting consists of a single server that hosts a single website. The perk to having a dedicated server is that the entire computer is focused on giving your website the best possible performance. While dedicated hosting can be somewhat expensive (see pricing), it is worth the cost if your website demands very fast page-load times, a dedicated IP, and the means to handle a lot of traffic, like upwards of 100,000 visitors per month.\r\n\r\n3. VPS Hosting (Cloud)
\r\n\r\nVPS hosting is the most difficult to describe out of the three types of hosting. First, VPS stands for “Virtual Private Server.” Basically, a VPS has a huge amount of computing resources you can purchase a portion of for a price. Imagine a computer with thousands of processors, terabytes of RAM, and unlimited hard drive space. For a monthly price, you can reserve as much of that computer as you need (see pricing).\r\n\r\nWhat is really happening is hundreds of computers are networked together and appear as a single resource. The advantage of VPS hosting is you can scale from small to large websites without having to switch servers. Also, with a VPS you have a huge number of options as far as software and hardware go, and you usually pay by the hour instead of having a monthly fee.\r\n\r\nVPS hosting is good for the more technically inclined and usually caters to programmers and web designers.', 'anjan'), (2, 'Types of Hosting Copy 2', 'The three types of hosting that are generally available are: Shared, Dedicated, and Virtual Private Servers (VPS).\r\n\r\nThese three options combine to cover small, medium, and large websites. Usually, a website size can be determined by the number of monthly visitors. Don’t be afraid to fall in the small section, as 99.9 percent of websites are considered small and it is significantly cheaper!\r\n1. Shared Hosting
\r\n\r\nShared hosting is by far the most common option for small businesses, individuals, and even some popular websites. Shared hosting is many websites hosting on a single server (remember server just means computer). The advantage to using shared hosting is it makes it extremely cheap because of the shared resources (see pricing).\r\n\r\nShared hosts can handle websites that run WordPress, Joomla, or others and also make this process very easy to set up. A shared host can handle up to 30,000 visitors per month, which covers most websites. If you are just getting started with hosting, you should take a close look at shared hosting for its value and performance.\r\n\r\n2. Dedicated Hosting
\r\n\r\nDedicated hosting consists of a single server that hosts a single website. The perk to having a dedicated server is that the entire computer is focused on giving your website the best possible performance. While dedicated hosting can be somewhat expensive (see pricing), it is worth the cost if your website demands very fast page-load times, a dedicated IP, and the means to handle a lot of traffic, like upwards of 100,000 visitors per month.\r\n\r\n3. VPS Hosting (Cloud)
\r\n\r\nVPS hosting is the most difficult to describe out of the three types of hosting. First, VPS stands for “Virtual Private Server.” Basically, a VPS has a huge amount of computing resources you can purchase a portion of for a price. Imagine a computer with thousands of processors, terabytes of RAM, and unlimited hard drive space. For a monthly price, you can reserve as much of that computer as you need (see pricing).\r\n\r\nWhat is really happening is hundreds of computers are networked together and appear as a single resource. The advantage of VPS hosting is you can scale from small to large websites without having to switch servers. Also, with a VPS you have a huge number of options as far as software and hardware go, and you usually pay by the hour instead of having a monthly fee.\r\n\r\nVPS hosting is good for the more technically inclined and usually caters to programmers and web designers.', 'anjanraj'), (3, 'Types of Hosting Copy 3', 'The three types of hosting that are generally available are: Shared, Dedicated, and Virtual Private Servers (VPS).\r\n\r\nThese three options combine to cover small, medium, and large websites. Usually, a website size can be determined by the number of monthly visitors. Don’t be afraid to fall in the small section, as 99.9 percent of websites are considered small and it is significantly cheaper!\r\n1. Shared Hosting
\r\n\r\nShared hosting is by far the most common option for small businesses, individuals, and even some popular websites. Shared hosting is many websites hosting on a single server (remember server just means computer). The advantage to using shared hosting is it makes it extremely cheap because of the shared resources (see pricing).\r\n\r\nShared hosts can handle websites that run WordPress, Joomla, or others and also make this process very easy to set up. A shared host can handle up to 30,000 visitors per month, which covers most websites. If you are just getting started with hosting, you should take a close look at shared hosting for its value and performance.\r\n\r\n2. Dedicated Hosting
\r\n\r\nDedicated hosting consists of a single server that hosts a single website. The perk to having a dedicated server is that the entire computer is focused on giving your website the best possible performance. While dedicated hosting can be somewhat expensive (see pricing), it is worth the cost if your website demands very fast page-load times, a dedicated IP, and the means to handle a lot of traffic, like upwards of 100,000 visitors per month.\r\n\r\n3. VPS Hosting (Cloud)
\r\n\r\nVPS hosting is the most difficult to describe out of the three types of hosting. First, VPS stands for “Virtual Private Server.” Basically, a VPS has a huge amount of computing resources you can purchase a portion of for a price. Imagine a computer with thousands of processors, terabytes of RAM, and unlimited hard drive space. For a monthly price, you can reserve as much of that computer as you need (see pricing).\r\n\r\nWhat is really happening is hundreds of computers are networked together and appear as a single resource. The advantage of VPS hosting is you can scale from small to large websites without having to switch servers. Also, with a VPS you have a huge number of options as far as software and hardware go, and you usually pay by the hour instead of having a monthly fee.\r\n\r\nVPS hosting is good for the more technically inclined and usually caters to programmers and web designers.', 'anjankumar');
PHP MySQL Display Limited Words with Read More Link |
1.connect.php
2.index.php
3.topic.php
4.style.css
Now copy the below codes for your Differnts Files.
Codes for connect.php
We use the below codes for established connection between database and server.<?php $host="localhost"; //Host name $user="root"; //MySQL Username. root is Default Value $pass=""; //MySQL Password $dbname="tutorial"; //Database Name //MySQL Connect mysql_connect("$host","$user","$pass")or die("Failed to Connecting Server"); //selecting Database mysql_select_db("$dbname")or die("Failed to Select Database"); ?>
codes for index.php
index.php files we use to display data from topic table with PHP read more link.<?php include("connect.php"); $sql="SELECT*FROM topic ORDER by ID DESC"; $result=mysql_query($sql); ?> <html> <head> <title>PHP MySQL Display Data With Read More Link</title> <link rel="stylesheet" href="style.css" type="text/css"/> </head> <body> <div class="container"> <?php while($row=mysql_fetch_array($result)) {?> <div class="topic"> <h2>Please Read Our Latest Post</h2> <?php $string = $row['description'];//Getting Description from Database as $string ?> <a href=topic.php?id=<?php echo $row['id'];?>><h3><?php echo $row['title'];?></h3></a> <p> <?php //Display Limited Text With Read More Link.We Will Display Here 300 Letter echo substr($string, 0, 350) ?><br/><div class="morebtn"><a href=topic.php?id=<?php echo $row['id'];?>>Read More</a></div> </p> Written by:<?php echo $row['creator'];?> <hr/> <div> <?php }?> <div> </body> </html>
codes for topic.php
when user click on read more link the user will see full topic here.<?php include("connect.php"); $id=$_GET['id']; //Getting ID Value From Index page $sql="SELECT*FROM topic WHERE id='$id'"; //Getting Result form MySQL database By ID $result=mysql_query($sql); ?> <?php while($row=mysql_fetch_array($result)) //Fetching Result from MySQL Table to Display {?> <html> <head> <title><?php echo $row['title']; //Post Title Here?> </title> <link rel="stylesheet" href="style.css" type="text/css"/> </head> <body> <div class="container"> <div class="topic"> <h2><?php echo $row['title']; //Post Title Here?></h2> <p> <?php echo $row['description']; //Post Description Here?> </p> Written by:<?php echo $row['creator'] ;////Post Creator Name?> <hr/> <div> <?php }?> <div> </body> </html>
codes for style.css
We add some css codes to design our index and topic page..container{ background:#F0F0F0; width:600px; text-align:justify; } .morebtn{ background-color: #adad85; border: none; font-size:20px; color: white; padding: 8px; width:90px; text-decoration: none; margin:3px; cursor: pointer; } .morebtn:hover{ background:#993300; } p{ background:#d6f5d6; text-align:left; border:1px solid black; } h3{ background:#52527a; padding: 8px; color:white; }
If you face any Problems plaese Comments us. Keep visiting for Next Tutorial.Thank You.
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.