Jump to content


Photo

LEFT, WORDWRAP


  • Please log in to reply
3 replies to this topic

#1 be@rbrick

be@rbrick
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 04 May 2006 - 06:39 AM

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. so i only want to display the first 50 - 70 words out of that on my page.

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.

so here is my basically code for a meantime :

<?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.

n here is the output.

XXXXXX
Take 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.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 May 2006 - 03:54 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 04 May 2006 - 09:55 PM

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

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 05 May 2006 - 11:22 PM

[!--quoteo(post=371388:date=May 4 2006, 04:55 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ May 4 2006, 04:55 PM) View Post[/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?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users