Jump to content

Limiting Words


greenday

Recommended Posts

Hi, I am trying to get a list of news stories from a database and list them, limiting them to a just 100 characters, and rounding them off to the nearest whole sentance, with a Read More » link to read in full. I have written the code, but its not working. Any help would be appreciated, thanks.

 

SQL Code:

 

mysql_select_db($database_aopn, $aopn);

$query_listofcategory = "SELECT article_id , article_title , article_date , thumb , SUBSTRING_INDEX(article_content,'.',100) FROM articles WHERE entertainment = 'Y' and thumb != '' ORDER BY article_date DESC limit 1";

$listofcategory = mysql_query($query_listofcategory, $aopn) or die(mysql_error());

$row_listofcategory = mysql_fetch_assoc($listofcategory);

$totalRows_listofcategory = mysql_num_rows($listofcategory);

 

 

PHP Code:

 

<?php echo $row_listofcategory['SUBSTRING_INDEX(article_content,.,100)']; ?>

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/48203-limiting-words/
Share on other sites

Change your query to...

 

$query_listofcategory = "SELECT article_id , article_title , article_date , thumb , SUBSTRING_INDEX(article_content,'.',100) AS content FROM articles WHERE entertainment = 'Y' and thumb != '' ORDER BY article_date DESC limit 1";

 

And your display code to....

 

<?php echo $row_listofcategory['content']; ?>

 

Your also aware you need a loop to loop through more than one record right?

 

 

Link to comment
https://forums.phpfreaks.com/topic/48203-limiting-words/#findComment-235641
Share on other sites

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.