I have attempted many solutions already given for this undoubtedly common problem, but have not had any luck. So I'm taking it to the brilliant minds around phpbuilder.com 🙂 Any help is much appreciated.
I want to return just the first 20 words from the field "content" in my table "news". Currently, my code is set up to return all data from the field. There are a few options I can use, for example:
select SUBSTRING_INDEX(content, ' ', 20) FROM news
This query works great and does just want I want, but I have no clue how to include it in the following code/query:
//start code
$query="SELECT id, subject, content, newsdate FROM news ORDER BY id desc";
$result=mysql_query($query, $db) or die('The query ' .$query .' returned this error: ' .mysql_error());
if ($myrow = mysql_fetch_array($result)) {
do {
printf("<img src=\"images/news2.gif\" align=\"left\"><font color=\"#990000\"><b><a href=\"http://www.oddshaped.com/index2.php?text=news&num=%s\"><font color=\"#990000\">%s</font></a>:</b></font> %s <br></b>%s<br><br>", $myrow["id"], $myrow["subject"], $myrow["newsdate"], $myrow["content"]);
} while ($myrow = mysql_fetch_array($result));
} else {
echo "Sorry, no news has been entered for today";
//end code
Anyone who helps gets a big hug in return 🙂
Thanks in advance!