greenday Posted April 23, 2007 Share Posted April 23, 2007 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 More sharing options...
trq Posted April 23, 2007 Share Posted April 23, 2007 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 More sharing options...
greenday Posted April 23, 2007 Author Share Posted April 23, 2007 thanks, Thorpe, works perfecly, and such a quick reply too. You have made my day Link to comment https://forums.phpfreaks.com/topic/48203-limiting-words/#findComment-235655 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.