Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/75791-mysql-and-php-help/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/75791-mysql-and-php-help/#findComment-383587
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/75791-mysql-and-php-help/#findComment-383588
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.