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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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