dazzclub Posted March 13, 2009 Share Posted March 13, 2009 Hi people, I would like to limit the amount of words i get from the database. Im using a query to get some news from my news table. Instead of retrieving the whole article i would like to retreive a certain amount of text and then display it as a paragraph... Below is the query im using the select some news content; function getHeadlines() { global $dbc; $query = "SELECT NewsID, NewsDate, NewsTitle, News FROM news ORDER BY NewsDate"; $result = mysqli_query ($dbc, $query)or die(mysqli_error() . "<p>With query:<br>$query"); while ($row = mysqli_fetch_array($result)) { //need to format the date on this function //get NewsID echo "<strong class=\"news_header\"><a href=\"news_article.php?news_article=$row[NewsID]\" title=\"erer\">$row[NewsTitle]</a></strong> <p class=\"date\">$row[NewsDate]</p> <p class=\"intro\">$row[News]</p> "; } } I would like to apply the wordwarp() function to $row[News] some thing like this $News =$row["News"]; $NewsShort = wordwrap($News, 10); Im just having some trouble applying it....so i thought i would create a function just for that purpose and thats where i have tried to implement the code above...to no avail... so my function for this currently stands at.. function shortenNewsContent() { global $dbc; $query = "SELECT News FROM news"; $result = mysqli_query ($dbc, $query)or die(mysqli_error() . "<p>With query:<br>$query"); while ($row = mysqli_fetch_array($result)) { return $row; $NewsShort = wordwrap($row, 19); echo "$NewsShort"; } } Any pointers would be nice. Thank you Link to comment https://forums.phpfreaks.com/topic/149227-using-wordwrap-to-limit-amount-of-words-being-retrieved/ Share on other sites More sharing options...
jackpf Posted March 13, 2009 Share Posted March 13, 2009 Do you actually just want to limit the amount of characters shown? If so, you can just use substr() to achieve this... Link to comment https://forums.phpfreaks.com/topic/149227-using-wordwrap-to-limit-amount-of-words-being-retrieved/#findComment-783656 Share on other sites More sharing options...
dazzclub Posted March 13, 2009 Author Share Posted March 13, 2009 characters you mean , a, b, c, 1, 2, 3, etc now. Would just like to limit whole words if possible... for example sake, if i had got this to work the output would appear like this Dazzclub is rubbish at php but he is trying so..... Thanks for your reply Link to comment https://forums.phpfreaks.com/topic/149227-using-wordwrap-to-limit-amount-of-words-being-retrieved/#findComment-783658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.