Re: [PHP] Displaying few words from record in mySQL

2003-03-08 Thread Nik Makepeace
On Sat, 2003-03-08 at 05:21, Rahul.Brenda wrote:
 Kevin,
 
 Your program certainly makes very good sense to me. 

I have written an extension of the idea available at

http://nikmakepeace.com/goodies/abbreviate.phps

It takes 5 arguments: 
string to be abbreviated, 
length in characters to abbreviate to 
(-ve values mean reduce string by this many chars)
place you want to abbreviate at (end, start or middle), 
string used to abbreviate (included in the total length)
(default is ... html entity)
whether to enclose the abbreviation in the abbr element
(title includes the whole string for mouseover)

I hope you or anyone else likes it. Maybe some day I'll actually do some
proper work instead of writing silly utilities.

Nik




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Displaying few words from record in mySQL

2003-03-08 Thread chris
On Fri, 7 Mar 2003 10:22:01 -0800 (PST), Rahul.Brenda 
[EMAIL PROTECTED] wrote:

Glory  Supreme Power

What i'm looking to do is.. i want to display only the
first few words of the record in my mySQL database..
For example.. i have a table with a field title..
and let's say my last record has the value in title
field as
This is going to be really cool

What i want to display is

this is going...

Basically this is for News Headlines. I have a page
which displays news but on the first page of the site
i have to give the first few words of the last 4
articles in the news table..
How can i do this? I have seen this in a lot of places
but i dont know how to do this.
Thanks,
Rahul S. Johari
__
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
Make mysql do the work for you.

select substring_index(title, ' ', 20), author from news order by date desc 
limit 4
// this particular string selects everything before the first 20 spaces of 
your title.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Displaying few words from record in mySQL [WORKS]

2003-03-08 Thread Rahul.Brenda
Chris.. 

2 words for you.. WOW and WOW. 
This works real well.. thanks. I didn't know it was
possible through an SQL statement. 

Nik  Kevin, thanks a lot .. but this SQL Query works
too efficiently and fast. 

Thanks again.. 
Rahul S. Johari

 Make mysql do the work for you.
 
 select substring_index(title, ' ', 20), author from
 news order by date desc 
 limit 4
 // this particular string selects everything before
 the first 20 spaces of 
 your title.



__
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Displaying few words from record in mySQL

2003-03-07 Thread Rahul.Brenda
Glory  Supreme Power

What i'm looking to do is.. i want to display only the
first few words of the record in my mySQL database.. 

For example.. i have a table with a field title..
and let's say my last record has the value in title
field as 

This is going to be really cool 

What i want to display is 

this is going...

Basically this is for News Headlines. I have a page
which displays news but on the first page of the site
i have to give the first few words of the last 4
articles in the news table.. 

How can i do this? I have seen this in a lot of places
but i dont know how to do this. 

Thanks,
Rahul S. Johari


__
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Displaying few words from record in mySQL

2003-03-07 Thread Kevin Stone
- Original Message -
From: Rahul.Brenda [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, March 07, 2003 11:22 AM
Subject: [PHP] Displaying few words from record in mySQL


 Glory  Supreme Power

 What i'm looking to do is.. i want to display only the
 first few words of the record in my mySQL database..

 For example.. i have a table with a field title..
 and let's say my last record has the value in title
 field as

 This is going to be really cool

 What i want to display is

 this is going...

 Basically this is for News Headlines. I have a page
 which displays news but on the first page of the site
 i have to give the first few words of the last 4
 articles in the news table..

 How can i do this? I have seen this in a lot of places
 but i dont know how to do this.

 Thanks,
 Rahul S. Johari

I don't know how to do it within the SQL query.. or even if it's possible.
But you can always gather the results as normal and build a function within
php that chops up each line into words and uses the first few words as an
abreviative text.  If you want the strings to be of uniform length (or to
ensure a minimum length) then you could do something with the strlen() and
strpos() functions.  This simple function that I wrote cares only about the
number of words in the abreviation.  It's rather crude but you're welcome to
use it if it helps you..

function abreviate_text($str, $num_words)
{
// $str parameter must be an alpha numeric string
if (!is_string($str))
return false;

// $num_words parameter must be a non-zero integer value
if (!is_integer($num_words) || $num_words == 0)
return false;

// split the string on all single spaces
$words = explode(' ', $str);

// build abreviated text..
$abr = array();
for($i=0; $i$num_words; $i++)
{
$abr[] = $words[$i];
}
$abr = implode(' ', $abr);
$abr .= ...;

return $abr;
}

- Kevin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Displaying few words from record in mySQL

2003-03-07 Thread Rahul.Brenda
Kevin,

Your program certainly makes very good sense to me. 
However, 2 things i will need to ask you.. is that,
let's say i decide i want the first 4 words from the
record displayed.. for all the 4 rows i'm displaying..
where do i define that in your program?
And secondly, how do i make this program work on the
myrow[myfield] variable which will actually carry the
record from the database?

thanks,
Rahul
 
 I don't know how to do it within the SQL query.. or
 even if it's possible.
 But you can always gather the results as normal and
 build a function within
 php that chops up each line into words and uses the
 first few words as an
 abreviative text.  If you want the strings to be of
 uniform length (or to
 ensure a minimum length) then you could do something
 with the strlen() and
 strpos() functions.  This simple function that I
 wrote cares only about the
 number of words in the abreviation.  It's rather
 crude but you're welcome to
 use it if it helps you..
 
 function abreviate_text($str, $num_words)
 {
 // $str parameter must be an alpha numeric
 string
 if (!is_string($str))
 return false;
 
 // $num_words parameter must be a non-zero
 integer value
 if (!is_integer($num_words) || $num_words == 0)
 return false;
 
 // split the string on all single spaces
 $words = explode(' ', $str);
 
 // build abreviated text..
 $abr = array();
 for($i=0; $i$num_words; $i++)
 {
 $abr[] = $words[$i];
 }
 $abr = implode(' ', $abr);
 $abr .= ...;
 
 return $abr;
 }
 
 - Kevin
 


__
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php