Jump to content

Limit text in a cell field


BrianM

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/106688-limit-text-in-a-cell-field/
Share on other sites

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

Archived

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

×
×
  • 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.