How to set up a news system? A complete news system not only includes a news interface for browsing, it also includes powerful functions for controlling many functions and background management. So how are the sub-functions within these functions scheduled and allocated? Let’s introduce the deployment control of each function. The implementation of the news system is simple, but it can also be said to be very complex.
The news system can be divided into three parts: administrator login system, news management system, and user browsing system. The whole process is simple:
1. Managers publish news --> database --> users browse news
2. Found problems --> log in to the management system --> edit and modify news.
The above process seems simple, but it is not that simple to implement. This is a system The development of the message board is far more complicated than the implementation of the message board, but the basic operating principle is the same as the message board. The top priority in the news release system lies in the planning of the database and the implementation of the management system.
What is the content of news now: news classification, information ontology. It is possible to include these two contents in one data table in the database, but it is not economical. Therefore, we can use two data tables to store the contents separately, one specifically to store the classification of news, and the other to store the ontology of the information. . How to call and realize the sharing of the content of dual tables? Use table association to realize this problem (this knowledge is not introduced here. Readers can refer to the knowledge content related to the database by themselves. The knowledge gained through one's own efforts is the most valuable, isn't it? ?)
The following is the implementation of the management function:
1. The first is the release of news
. This is composed of a series of submission forms, and it is divided into two categories: creating news categories and publishing news; after creating news categories, then It's very simple to publish relevant news in each category! It's not like this. Think about all the information ontology being concentrated in one data table. How to distinguish the categories of information? The table association mentioned above is very important here. Of course, this method is not needed. Creating an independent table for each category can also solve the problem. But is this cost-effective? How about maintainability and scalability?
The related calls of news classification and information ontology have caused trouble
., by the way, the solution is to make use of table associations.
2. Issues of editing, modification, and deletion.
This is the basic application of php+mysql knowledge. It is not difficult to implement these functions. I will not introduce too much here. What you need to pay attention to is how to deal with a category when changing or deleting it. What about the information ontology under it? Due to the use of table associations, processing these functions is as if they are processed in a table.
3. Multi-tasking
But what happens when many people edit a news item at the same time? The situation is that the database will only store the last edited content. If this happens, it will mean that the hard work of the previous editors has been in vain. Multi-tasking The solution to this problem is to take a preconceived approach, that is, those who enter the editor first have editing permissions, and those who enter later only have browsing permissions until the editing is completed. This function is very similar to Linux's permission control, isn't it?
There are several methods to complete this function: 1. Use cookies to control,2. Add permission control fields to the table. Of course, it is simpler to use cookies. The method and process of cookie implementation are as follows:
when an administrator enters the editor and sets the cookie, the program segment of the edit function determines the cookie value. If it is empty, editing is allowed. If it is not empty, editing is rejected and the editor exits. Then clear the cookies, and the cycle repeats; the multitasking function is an effective function, which can at least reduce the waste of time and manpower.
The implementation of the news browsing function is very simple. With the addition of the page turning function (which has been introduced on this site), the powerful news system is basically completed. It seems that a very important function is missing, which is the search engine. It is the wish of every website to have a powerful search engine, and the production of a powerful search engine is quite complicated and difficult. It involves many aspects such as efficiency, accuracy and speed.
The search engines introduced here will not involve such in-depth research, but only conduct precise queries for specific content. A complex and powerful search engine requires a lot of programming and database skills. Let’s start with a simple search engine. How does the search engine work? It receives the given keywords, searches within the given range, and then returns the search results.
The given keywords may be anywhere in the information content. How does the engine search? The following database statement is used here:
select * from table where (name like '%".$keyword."%');
name is the specific location to search, usually the field name, like '%".$keyword. "%' is pattern matching, that is, in the content Search for $keyword. Consider an example:
Find all titles containing the keyword good in the data table news:
select * from news where (title like '%good%');
This is a precise search, which can find all titles with good in the database. There is also a fuzzy search:
select * from news where (title like '%good');
You can also find results in this way.
Assuming that news contains fields such as title, message, user, etc., the above search scope is too narrow, because only the title is searched, and other content needs to be searched without making the operation too complicated. How to deal with it?
We noticed that any changing value in the program is processed by variables. This method also works here. You can transfer the range you want to search as a variable, so you have the following database syntax Got:
mysql_query("select * from news where ($name like '%".$keyword."%'));
$name stores the value of the field variable transmitted, and this variable value is dropped through the html select Submit the form to complete. What if you want to limit the search results to a certain time range? For example, if you want to find information within 5 days, do you still remember the database syntax used in the cookie introduction?
Yes. , the syntax of this union is as follows:
mysql_query("select * from news where ($name like
'%".$keyword."%') and time>date_sub('$time',interval 5 day)");
Where $time is the current time of the search: $time=date('Ymd H:i:s'); time is the field in which the database stores information time. Now replace $old with 5:
mysql_query("select * from news where ($name like
'%".$keyword."%') and time>date_sub('$time',interval $old day)");
Similarly, the value of $old is submitted for different limited times through the select submission form, thus completing this quite powerful search engine. Some more powerful search engines require the cooperation of programming skills. Readers can expand their own experiments through the above principles.