Jump to content

Using wordwrap to limit amount of words being retrieved


dazzclub

Recommended Posts

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 :)

 

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 :)

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.