Jump to content
xisto Community
Sign in to follow this  
fffanatics

Php Dynamic News Updating Using Mysql changing a sites news using MySQL and PHP

Recommended Posts

Hey everyone. It appears to me that everyone really know what they are doing in this forum and im a pretty new to this PHP and MySQL combo. I know some PHP but not MySQL....I am trying to make a new website but i want to be able to go to a certain update page and change the news on the main index. For example: - The main page show news updates of the last 10 post. - I go to the update page and then fill in the form and it will add this post to the top of the list and still only print the top 10.I have no clue how to do this with MySQL. At the moment i am doing it using a file but i know file reading is slow and annoying so i want to try to avoid it. Any help on how to do this would be wonderful or a link to website explaining it would be nice even if it points to an already written script because i can atleast study the code and write it for myself. Thanks for your help in advance

Share this post


Link to post
Share on other sites

See MySQL responds to some cool SQL syntax and is able to fetch exactly this set of information for you.

 

Say your table contains a couple of fields namely,

a. TopicID

b. TopicTitle

c. Message

d. PostDateTime

 

When you insert a new topic, TopicID gets increased by 1 (or whatever increment scheme you follow) and the Time+Date of posting gets inserted into the last column.

 

When you want to display the last 10 topics, you can use a simple statement:

SELECT TopicTitle FROM MyTable LIMIT 10 ORDER BY PostDateTime

The LIMIT 10 will select the only 10 Topic titles from the TopicTitle column which is ORDER BY PostDateTime - i.e. ordered by date and time of post. If the order is set to descending - this will effectively pull out you last 10 entries.

 

Try it and let me know.

Share this post


Link to post
Share on other sites

mysql tables: id,title,description


<?$q = mysql_query("select * from news order by id;");while($news = mysql_fetch_array($q)){echo "<a href=news.php?id=$news[id] target=_blank>$news[title]</a>";}?>

news.php
<?$num = stripslashes($id); // security reasons$q = mysql_query("select * from news where id=$num;");$news = mysql_fetch_array($q);?><?=$news[title]?><br><br><?=$news[description]?>

Try something like this, and you will just have to add your news on the database.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.