be@rbrick Posted May 4, 2006 Share Posted May 4, 2006 Dear all,Simply i have a small problem but a big headache actually to solve as for me. Here is the situation.1st - to connect to the database - done.2nd - to loop the data on descending order - done.3rd - To display the data from the database - done.4th - to limit the data display - not done, headache.- the data that i call from my database is description on something which have more than 200-300 words. [u]so i only want to display the first 50 - 70 words out of that on my page.[/u] i do surfin, read the tutorials n try, but in the end there is nothing works. my bad. here is the example that run on asp. <%=left(rsNews("newsContent"), 200)%>but i need it badly on php.[b]so here is my basically code for a meantime[/b] :<?php if (!empty($row_last_3['name']) and !empty($row_last_3['link'])){ ?><?php echo $row_last_3['name']; ?><br><?php echo $row_last_3['comments'];?>which is "comments" represent the description that i mention.[b]n here is the output. [/b]XXXXXXTake a trip back to the past by visiting XXXXXX. Brace yourself for an interesting and educational journey into XXXXXX colourful and vibrant culture, history and national history within the walls of XXXXX. Your visit will leave you mesmerized with the vibrant and colourful history and culture of XXXXX.thanx you. Quote Link to comment https://forums.phpfreaks.com/topic/9037-left-wordwrap/ Share on other sites More sharing options...
fenway Posted May 4, 2006 Share Posted May 4, 2006 Well, you can easily retrieve a trimmed column back from the DB with "LEFT(comments, 50) AS trimmedComments", but that's characters, not words. If you're looking for words exactly, you'd have to count them out first, and find the position in your column first. Otherwise, 5 characters per word may be a valid approximation. Quote Link to comment https://forums.phpfreaks.com/topic/9037-left-wordwrap/#findComment-33352 Share on other sites More sharing options...
wickning1 Posted May 4, 2006 Share Posted May 4, 2006 I would probably pull the first 800 characters or so and then trim any partial word at the end in PHP.<?php$descr = database_call();echo preg_replace('/\s\S*$/', '', $descr);?> Quote Link to comment https://forums.phpfreaks.com/topic/9037-left-wordwrap/#findComment-33427 Share on other sites More sharing options...
fenway Posted May 5, 2006 Share Posted May 5, 2006 [!--quoteo(post=371388:date=May 4 2006, 04:55 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ May 4 2006, 04:55 PM) [snapback]371388[/snapback][/div][div class=\'quotemain\'][!--quotec--]I would probably pull the first 800 characters or so and then trim any partial word at the end in PHP.<?php$descr = database_call();echo preg_replace('/\s\S*$/', '', $descr);?>[/quote]wickning1 is back! Where have you been hiding for the past month or so? Quote Link to comment https://forums.phpfreaks.com/topic/9037-left-wordwrap/#findComment-33760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.