Controling the size of a post
Moderator: General Moderators
Controling the size of a post
On a certain page I print out the contents of posts submitted. The post DB field is a medium text. However on this one page I dont want it to display a long post. Only like the first so many lines of it. Then have a link for them read more about it. Is this a possablity with PHP or do I need to use javascript?
-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
this should hook you up
basically if the field is bigger than 27 characters, I chop it off and add ...
at the end so people know it continues
then the link could just be
Code: Select all
<?php
if(strlen($VARIABLE)) > 27)
{
$new_cat_name = substr($VARIABLE,0,27) . '...';
}
?>basically if the field is bigger than 27 characters, I chop it off and add ...
at the end so people know it continues
then the link could just be
Code: Select all
<a href="linktopage.php"><?=$new_cat_name?></a>I tried. Here is what I have.
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<?
include ("config.php");
// fetch the results from the database.
mysql_connect($DBhost,$DBuser,$DBpass) or
die("Unable
to connect to database");
@mysql_select_db("$DBname") or die("Unable to select
database");
$sqlquery = "SELECT * From posts where approved='Y' order by 'post_id' DESC";
$result=mysql_query($sqlquery);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$poster=mysql_result($result,$i,'poster');
$poster=htmlspecialchars($poster);
$post=mysql_result($result,$i,'post');
$title=mysql_result($result,$i,'title');
$timestamp=mysql_result($result,$i,'timestamp');
$type=mysql_result($result,$i,'type');
if ($i < 5) { ?>
<tr>
<td valign="top"><font color="green" size="4"><? echo "$type"; ?>: </font>
<font size="4" class="capital"><? echo "$title"; ?><br></font>
<font color="#999999">Posted by:</font>
<font color="#FF9933"><? echo "$poster"; ?></font>
<font color="#999999">on</font>
<font color="#999999"> <? echo "$timestamp"; ?><br>
</font> <br>
<?
if(strlen($post)) > 100)
{
$new_post = substr($post,0,100) . '...';
echo $new_post; echo "<br>";
}
?>
<hr style="COLOR: sienna" noshade><BR>
</td></tr> <? } ?>
<?
++$i;
}
?>
</table>
When I try to look at the page this is on I get parse error on line 33 which is this one
if(strlen($post)) > 100)
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<?
include ("config.php");
// fetch the results from the database.
mysql_connect($DBhost,$DBuser,$DBpass) or
die("Unable
to connect to database");
@mysql_select_db("$DBname") or die("Unable to select
database");
$sqlquery = "SELECT * From posts where approved='Y' order by 'post_id' DESC";
$result=mysql_query($sqlquery);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$poster=mysql_result($result,$i,'poster');
$poster=htmlspecialchars($poster);
$post=mysql_result($result,$i,'post');
$title=mysql_result($result,$i,'title');
$timestamp=mysql_result($result,$i,'timestamp');
$type=mysql_result($result,$i,'type');
if ($i < 5) { ?>
<tr>
<td valign="top"><font color="green" size="4"><? echo "$type"; ?>: </font>
<font size="4" class="capital"><? echo "$title"; ?><br></font>
<font color="#999999">Posted by:</font>
<font color="#FF9933"><? echo "$poster"; ?></font>
<font color="#999999">on</font>
<font color="#999999"> <? echo "$timestamp"; ?><br>
</font> <br>
<?
if(strlen($post)) > 100)
{
$new_post = substr($post,0,100) . '...';
echo $new_post; echo "<br>";
}
?>
<hr style="COLOR: sienna" noshade><BR>
</td></tr> <? } ?>
<?
++$i;
}
?>
</table>
When I try to look at the page this is on I get parse error on line 33 which is this one
if(strlen($post)) > 100)
-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
got an extra ) in there, sorry about that
use:
use:
Code: Select all
<?php
if(strlen($post) > 100)
?>