headlines as links

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ahmed
Forum Newbie
Posts: 3
Joined: Tue Apr 20, 2004 1:03 am

headlines as links

Post 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
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post 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.
ahmed
Forum Newbie
Posts: 3
Joined: Tue Apr 20, 2004 1:03 am

Post by ahmed »

thanx steveo
i'll chek that out

ahmed
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
ahmed
Forum Newbie
Posts: 3
Joined: Tue Apr 20, 2004 1:03 am

Post by ahmed »

thanx Mark
yr code is very easy to understand

ahmed
Post Reply