Page 1 of 1

want help

Posted: Sun Dec 12, 2004 12:39 am
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]

Posted: Sun Dec 12, 2004 12:58 am
by Bennettman
$Info = substr($rowNews->n_article, 0, 20);

etc etc.

Posted: Sun Dec 12, 2004 1:04 am
by itsmani1
thanks man now let me try this ? hope it will work :)

Posted: Sun Dec 12, 2004 1:21 am
by itsmani1
thanks man its working :)

Posted: Sun Dec 12, 2004 7:26 am
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