Jump to content

LEFT, WORDWRAP


be@rbrick

Recommended Posts

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]

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[!--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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.