Page 1 of 1

Showing Part Of The Content For Description By Mysql

Posted: Thu Sep 29, 2011 11:51 am
by Alg0r1thm
Hi brothers ,
I have a file archive.php that contains the last posts and it shows the title of the subjects but I wanna also show the part of the subject description I mean part of the text in archive.php , Assume that is archive.php :

Betterphp
Betterphp is a free php tutorial provider ...
________________________
Youtube
Hi, in this post I introduce you with youtube ...

pages : 1 2


I want to show short description that is fetched from the database with what mysql function can I do it ?

I hope you understand ,

Thanks in advance

Re: Showing Part Of The Content For Description By Mysql

Posted: Thu Sep 29, 2011 4:18 pm
by JelvinJS7
In the query, use the JOIN function. It works the same as the php substr function; first parameter is the field, second is the amount of characters you want.

Re: Showing Part Of The Content For Description By Mysql

Posted: Thu Sep 29, 2011 6:56 pm
by Alg0r1thm
Can you show me an example ?

Thanks

Re: Showing Part Of The Content For Description By Mysql

Posted: Thu Sep 29, 2011 7:22 pm
by JelvinJS7
I meant to say left… not join. :oops:
SELECT `title`, `date`, LEFT(`description`, 30) FROM `posts` WHERE `post_id` = {$id}


Re: Showing Part Of The Content For Description By Mysql

Posted: Fri Sep 30, 2011 6:02 pm
by jacek
You can also do
SELECT `title`, `date`, SUBSTRING_INDEX(`description`, ' ', 30) FROM `posts` WHERE `post_id` = {$id}
which would give you the first 30 whole words. It just looks a little nicer I think :)