|
|
Php Dynamic News Updating Using Mysql - changing a sites news using MySQL and PHP | ||
Discussion by fffanatics with 3 Replies.
Last Update: April 24, 2005, 12:11 pm | |||
![]() |
|
|
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
- 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
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:
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.
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:
CODE
SELECT TopicTitle FROM MyTable LIMIT 10 ORDER BY PostDateTimeThe 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.
Thanks for the response. I will try that as soon as a i get a chance and post its results. Once again thanks for the help
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.
CODE
<?$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
CODE
<?
$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.
Similar Topics:
Php News Script
Php And Mysql Programming
Best Php And Mysql Editor For Noobs
Wc3 warcraft 3 scripting (1)
|
(2) Add Links
|
Loading...
HOME 





PHP Tutorials: jQuery: Get data from MySQL Database without refreshing
Content Management System with Dreamweaver CS4, PHP, MySQL and FCKEditor - Video 4
Slick Website Template with Admin Panel - Global Settings

