PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Sun Dec 12, 2004 12:39 am
nigma | Help us, help you. Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]Code: Select all
<?
$qryNews = "SELECT * FROM tbl_news WHERE n_show='1'";
$resNews = mysql_query($qryNews);
$cntNews = mysql_num_rows($resNews);
if($cntNews > 0){
while ($rowNews = mysql_fetch_object($resNews)) {
$Headline = $rowNews->n_headline;
$NewsDate = $rowNews->n_date;
$ShowIt = $rowNews->n_show;
$NewsID = $rowNews->n_id;
$Info = $rowNews->n_article;
?>
see the above code:
what i am doing is :
i am getting news headline, news date, news id and news details in the var named info. what i want to do is that i want to get only first 20 characters of the info/n_artivle.
can any one help me to solve the issue.
Regards
nigma | Help us, help you. Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Bennettman
Forum Contributor
Posts: 130 Joined: Sat Jun 15, 2002 3:58 pm
Post
by Bennettman » Sun Dec 12, 2004 12:58 am
$Info =
substr ($rowNews->n_article, 0, 20);
etc etc.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Sun Dec 12, 2004 1:04 am
thanks man now let me try this ? hope it will work
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Sun Dec 12, 2004 1:21 am
thanks man its working
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Dec 12, 2004 7:26 am
there is no need to retrieve the whole article (which can be huge)
with MySQL SUBSTRING you can
Code: Select all
SELECT SUBSTRING(article, 20) AS article FROM foo
or if you want (around) the 20 first words
Code: Select all
SELECT SUBSTRING_INDEX(article,' ',20) as article FROM foo