Jump to content

Archived

This topic is now archived and is closed to further replies.

be@rbrick

LEFT, WORDWRAP

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
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);
?>

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

×

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.