adam291086 Posted November 2, 2007 Share Posted November 2, 2007 Hello, I am wanting to pull some information from a new database. I want to get all the latest new article and display them on the home page within a table. That i can do. The problem i am having is that i only want to show some of the news article, like 20 words from the content and then display a more link to the full article. How can i do this? I dont want you to do it for me but push me in the right direction Thanks Quote Link to comment https://forums.phpfreaks.com/topic/75791-mysql-and-php-help/ Share on other sites More sharing options...
pocobueno1388 Posted November 2, 2007 Share Posted November 2, 2007 Well...to select them from the DB, you would use a query like this SELECT * FROM news ORDER BY newsID DESC LIMIT 10 I'm assuming you know how to display all the records into an HTML table. To get the 20 words, you would use the function substr() http://us.php.net/substr Then to make the "View More" link, you would just use the uniqueID from the table in the link. You would have to setup a page that gets the uniqueID from the URL and pulls that information from the database to display the full article. Quote Link to comment https://forums.phpfreaks.com/topic/75791-mysql-and-php-help/#findComment-383587 Share on other sites More sharing options...
Psycho Posted November 2, 2007 Share Posted November 2, 2007 Well, I would first check the length of the article to be displayed. If it is less than 20 characters than show all of it. If it is more than 20 characters then I would want to get the beginning text of the article up to 20 characters, but I would break it at a word, and also append elipses to the end. Creating a link is simple, there should be a page which displays a full article and afccepts the article id ont he query string. Some functions you would want to use: substr(): http://us.php.net/manual/en/function.substr.php strlen(): http://us2.php.net/strlen strrchr(): http://us2.php.net/manual/en/function.strrchr.php Quote Link to comment https://forums.phpfreaks.com/topic/75791-mysql-and-php-help/#findComment-383588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.