PDA

View Full Version : Limit displayed text from recordset


parabol
02-27-2007, 09:34 PM
Hi there,

Im hoping someone can help me,

I'm trying to limit the amount of displayed text from a php database.
To be able to limit the text for example 80 characters.

My Website News
"This is some of the text from a field in my table, it is showing about 80 characters.... [Click To Read More] "

Is there an extention for Dreamweaver or a function in weaver to limit the amount of displayed text?

Thanks in advance
Warren

davidj
02-27-2007, 09:46 PM
Is there an extention for Dreamweaver or a function in weaver to limit the amount of displayed text?



probably, maybe .. who knows!

i do know its possible in PHP though

post the code

parabol
02-27-2007, 10:06 PM
Basic Layout for where text will be shortened in News Section:



<?php require_once('Connections/Farout.php'); ?>
<?php
mysql_select_db($database_Farout, $Farout);
$query_rsFOFnews = "SELECT * FROM fof_news ORDER BY id DESC";
$rsFOFnews = mysql_query($query_rsFOFnews, $Farout) or die(mysql_error());
$row_rsFOFnews = mysql_fetch_assoc($rsFOFnews);
$totalRows_rsFOFnews = mysql_num_rows($rsFOFnews);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="32">Limted Text from News</td>
</tr>
<tr>
<td height="61"><?php echo $row_rsFOFnews['news']; ?>.... <a href="webnews.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."id=".$row_rsFOFNews["id"]?>">[Read More Here]</a></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsFOFnews);
?>

davidj
02-27-2007, 10:14 PM
where you have ...

<?php echo $row_rsFOFnews['news']; ?>.... <a href="webnews.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."id=".$row_rsFOFNews["id"]?>">[Read More Here]</a>

add this ... (notice the substr)

<?php echo substr($row_rsFOFnews['news'],0,30); ?>.... <a href="webnews.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."id=".$row_rsFOFNews["id"]?>">[Read More Here]</a>

explaination of substr...
substr($stringvar, 0, 10);

$stringvar is the string variable you want to perform a chop on. The first numeric is the starting point and 0 is the first char of the string. The second numeric is the count of how many letters you want to display.

parabol
02-27-2007, 10:21 PM
That is awesome !!! Thankyou

problem solved
Thanks Davidj