Page 1 of 1

headlines as links

Posted: Tue Apr 20, 2004 1:03 am
by ahmed
hi all

im quite new to php.

im trying to add some dynamic content to my home page
i have a lot of daily news items in a mysql db
what i want is to show the headlines of each news item as links and the first sentence.

i hope someone can help me.

thanx
ahmed

Posted: Tue Apr 20, 2004 1:08 am
by Steveo31
This will help with just the first few words/sentences:

Code: Select all

function truncate_small ($string, $max = 50, $rep = '') {
   $leave = $max - strlen ($rep)
   return substr_replace($string, $rep, $leave);
}
And as for the getting of data... check around. You need a SELECT query.

Posted: Tue Apr 20, 2004 4:12 am
by ahmed
thanx steveo
i'll chek that out

ahmed

Posted: Tue Apr 20, 2004 4:22 am
by JayBird
Would be better and neater to do it int he query itself!

Code: Select all

$sql = "SELECT *, SUBSTRING_INDEX(story, ' ', 10) AS new_story FROM news";
This will display the first 10 words

Mark

Posted: Tue Apr 20, 2004 10:13 am
by ahmed
thanx Mark
yr code is very easy to understand

ahmed