Limit echo, not by substr & not by limiting rows.?.?.?


Joined
May 29, 2007
Messages
1
Reaction score
0
Heya,
I'm working on a page which calls article titles and text from a MySQL DB using PHP. It's kinda difficult to explain what I need, but I'll try.

I need the articles to fit into a set height (& width) div. The articles vary in length. Some are relatively lengthy, some are short.

I need the ability to, if the displayed articles are short, display multiples, up to the length allowed by the div. If the top article is lengthy, it should truncate at that same point.

I've tried adding:

if(strlen($row_ssh_news['content'])>2000){
echo substr($row_ssh_news['content'], 0, 2000) . '…';
}
else {
echo $row_ssh_news['content'];
}

This works beautifully if I'm only displaying one db row, it only checks the string length on a "per row" basis. But if I have it set to display multiple db rows, this condition is useless, the content doesn't get correctly truncated, only if a row's content length exceeds the conditional.

The layout of the div is simple:


----div beginning----
Title
Content

Title
Content

Title
Content


Link to open full content in separate window
----end of allotted space------



I know this could be better explained, but I'm not finding the correct words. Hopefully someone here will understand what I'm talking about.......

Basically I need to display as many articles as possible, up to the set height of the div, then truncate and print a link to open all results in a new window. I have everything but the code to truncate.....

Thanks in advance for whatever help you may provide!
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top