0

I'm trying to figure out a way to limit the amount of information pulled from a database, that is displayed within a table as like an overview type function.

Let's say the information pulled from the database has 1000 words, but I only want the table to display 150 characters and then display "..." to indicated there is more information.

Is this possible? Like a maxlength or overflow property?

Thanks.

Adariel Lzinski
  • 1,031
  • 2
  • 19
  • 43
  • I believe this link will help: http://stackoverflow.com/questions/3161816/get-first-n-characters-of-a-string – iJakeUjake Mar 12 '15 at 21:49

1 Answers1

1

You could use substr() to limit the length of returned items.

$result = mysql_query("SELECT * FROM table");  
while($row = mysql_fetch_array($result)) {  
    // returns the first 150 characters followed by "..."  
    $strIn = $row['database_column'];  
    $strOut = substr($strIn, 150) . '...';  
    echo('<p>'.$strOut.'</p>');    
}

If you want to check to make sure it splits properly between words, you'll want to do some further string manipulation.

Adam Konieska
  • 2,805
  • 3
  • 14
  • 27