BrianM Posted May 21, 2008 Share Posted May 21, 2008 Anyone know of a way to limit the text that is displayed in a cell on a page being output from a row in a MySQL database? Say instead of displaying 100 characters it will limit it to display 15 on the page. Here is what I have -- and I'm wanting the last row, report, to display only 15 characters or so on the web page, and not the entire report. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>MPS - View Reports</title> </head> <?php mysql_connect('localhost', 'brian', '') or die(mysql_error()); mysql_select_db('mps') or die(mysql_error()); ?> <body> <?php mysql_query('ALTER TABLE mps_reports ORDER BY ID'); $result = mysql_query('SELECT * FROM mps_reports'); echo "<table border='1' cellpadding='0' cellspacing='0'> <tr> <th> Report ID </th> <th> Date </th> <th> Preview </th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ID'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['report'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
abid786 Posted May 21, 2008 Share Posted May 21, 2008 Substr, I think. while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ID'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; $smReport = substr($row[report], 0, 15); echo "<td>" . $smReport . "</td>"; echo "</tr>"; } I hope this is what you were looking for Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 21, 2008 Author Share Posted May 21, 2008 echo "<td><center> " . substr($row['report'], 0, 25) . " </center></td>"; The above worked, similar to what you provided, but excluding the variable. =) Thank you, abid786! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.