473,595 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to break text from database and have "Read More" button?

ilya Kraft
134 New Member

I came over this problem.
I'll try to make it as simple as I can.
Say there is a page called submit-article.php where users enter their text in the field. It goes in database and so on...
Than I display it in div on index.php page. How can I limit text that displays on index.php page to 200 characters? And than have a "Read More button" < When clicked expands div to show all text.
I will attach image that shows what I mean.

Thank You
Attached Images
File Type: jpg Text_break_example.jpg (91.2 KB, 7693 views)
May 2 '11 #1
11 32940
12,516 Recognized Expert Moderator MVP
You could store it in a variable and then display only the first 200 characters. Then, when they click the button to see more, it just replaces what's in the div with the full text.
May 2 '11 #2
ilya Kraft
134 New Member
Yeh, I kind of know the logic of it, my problem is in code. Here is what I have got so far:

Expand|Select|Wrap|Line Numbers
  1. $sql_text = mysql_query("SELECT * FROM memberPosts WHERE id='$id'");
  2. $text = $row["text_body"];
  4. $textdisplaylist = '<div>'.$text.'<br><a href="#">Read More</a></div>';
My question is, how to limit text to 200, than how to expan div when Read More is clicked, than How to insert full text instead of mini text. Quiet a lot of questions huh ;) But this are the parts I cant understand.

Thank You
May 2 '11 #3
18 New Member
if(strlen($text ) > 200)
$textdisplaylis t = '<div>'.substr( $text,0,200).'< br><a href="#">Read More</a></div>';
//no point of having read more button here cuz there nothing more to read :)
$textdisplaylis t = '<div>'.$text.' </div>';
May 2 '11 #4
ilya Kraft
134 New Member
This shows how to limit it to 200 characters right?
What is that strlen function?
But this just limits text to 200 right?
What I meant was. Say I have 500 char text, I want to show first 200 characters of it on the first page, but when someone clicks Read More button it expands down and shows all text, like on this image here

May 2 '11 #5
12,516 Recognized Expert Moderator MVP
The strlen function tells you how many characters are in a string.

What you need to do is write it into the javascript of the page. You'll also need an onclick function on the read more that will a) put in the rest of the text and b) hide the "read more" or toggle it to "show less"
May 2 '11 #6
2 New Member
why are you processing it in php??
use Mysql function for that(I dont remember d function name but there is a one..guranteed. .plz google it)
and when user click Read more, then retrieve d whole field data
May 2 '11 #7
12,516 Recognized Expert Moderator MVP
You can't just use JavaScript for it. At some point you're going to need a server side script to retrieve the actual value. Which is what they're doing.
May 3 '11 #8
ilya Kraft
134 New Member
I found A solution for this.

First you want to setup the basic structure of your content so that you can enable this functionality.
Expand|Select|Wrap|Line Numbers
  1. <div class="more-less">
  2.     <div class="more-block">
  3.         <p>The Content</p>
  4.     </div>
  5. </div>
Anything that you place into the “more-block” div will be expandable. The “more-less” div is needed to hold the More/Less link and the [...], which is added using the jQuery, saving you the time of adding those small parts.

For explanation of the jQuery, view the comments throughout the code below.

Expand|Select|Wrap|Line Numbers
  1. $(function(){
  3. // The height of the content block when it's not expanded
  4. var adjustheight = 80;
  5. // The "more" link text
  6. var moreText = "+  More";
  7. // The "less" link text
  8. var lessText = "- Less";
  10. // Sets the .more-block div to the specified height and hides any content that overflows
  11. $(".more-less .more-block").css('height', adjustheight).css('overflow', 'hidden');
  13. // The section added to the bottom of the "more-less" div
  14. $(".more-less").append('
  15. […]
  17. ');
  18. // Set the "More" text
  19. $("a.adjust").text(moreText);
  21. $(".adjust").toggle(function() {
  22.         $(this).parents("div:first").find(".more-block").css('height', 'auto').css('overflow', 'visible');
  23.         // Hide the [...] when expanded
  24.         $(this).parents("div:first").find("p.continued").css('display', 'none');
  25.         $(this).text(lessText);
  26.     }, function() {
  27.         $(this).parents("div:first").find(".more-block").css('height', adjustheight).css('overflow', 'hidden');
  28.         $(this).parents("div:first").find("p.continued").css('display', 'block');
  29.         $(this).text(moreText);
  30. });
  31. });
May 3 '11 #9
1 New Member
$sql_text = mysql_query("SE LECT * FROM memberPosts WHERE id='$id'");
$row=mysql_fetc h_array($sql)
$text = $row["text_body"];
<?php echo substr($text,0, 200);?><a href="#"?id=<?p hp echo $row['id']?>>Read More</a>

check this one
Mar 15 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: php newbie | last post by:
I am trying to write a cursor to update certain rows in a particular order as follows: (I need the cursor version, not SQL, as the update logic depends on the order of rows and some other conditions. I removed the Order-By clause from the statement to simplify it; it gives the same error message with or without it.) DECLARE prod_cursor CURSOR FORWARD_ONLY KEYSET FOR SELECT 1 FROM all_products WHERE p_qty = 0 FOR UPDATE
by: Rich | last post by:
Hi, I'm having problems with changing the Read Only properties. Running Winxp and i cannot get the "read only" to clear off a folder. The folder is one that i want to change the data in and it won't let me. I have two accounts on the main system and cannot change the properties from either administrator account. I have tried renaming the folder and putting it back into the program and it still won't work. All files in the folder are...
by: PeteCresswell | last post by:
I guess the good-right-and-holy path is a Read-Only user ID in the backend DB...but that's not in the cards right here right now. Meanwhile, I'd like to put up a "Look, but don't touch" DB for poking around. I would prefer to avoid MS Access's security because of portability issues. Anybody know of a way I could create a link that cannot update the
by: Vic | last post by:
Dear All, I have a database of laboratory records in Access 2000. There is one form which acts as an interface to input experimetal data. This form incorporates information from several tables. I have a flag (yes/no field) indicating whether a particular experiment (one record) is completed (ie all data belonging to that record is inputted and quality controlled). What I want is that when I change the flag to "yes" the particular record...
by: Stinky Pete | last post by:
I've mananged to get Access Run-time working on a Win 98 PC. I was stoked at that achievement, however I'm now stuck in that the files are opening Read only. That is, I can view all the records via the two forms I need but not change anything. Why? The command line for the user to access the file is simply as follows (from advice via msdn.microsoft.com) "C:\MS Runtime\Office10\MSACCESS.EXE" "Q:\QA Records Database\Vaccine...
by: Johannes Zellner | last post by:
Hi, can I make an object read-only, so that x = new_value fails (and x keeps it's orginal value)? This would be especially of interest for me for an object created by a c extension.
by: JanP | last post by:
Hello I'm new here and hope someone can help solve this problem. I built a database in MS Access 2000 and split it. Since I was upgraded to 2003, (the other user still has 2000) we cannot both use the database at the same time. At first we got the "Access 2003 Open Exclusive Error" but have resolved that one. Now we can both open our front ends, but only the first one in can update data. The other user gets a message saying "This...
by: ascll | last post by:
Hi, Do you guy know how to make a ASP.net 2.0 checkbox "read-only"? Thanks.
by: libish | last post by:
hi all, can any one help me in converting a directory to read only format. and also making a read only directory/file to read/write directory this is to avoid deleting a directory accidently.. my project is for windows mobile and is in c#.
by: UDontKnowJack | last post by:
Hey! I would like to make a copy of my database a "Read only" version. Without going into every form/table and at properties make it a read only. There has to be another way to make the whole database a "read only" at once?! Thanks
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.