want help

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

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

want help

Post by itsmani1 »

nigma | Help us, help you. Please use

Code: Select all

and

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

and

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 »

$Info = substr($rowNews->n_article, 0, 20);

etc etc.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

thanks man now let me try this ? hope it will work :)
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

thanks man its working :)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

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
Post Reply