Add and delete a vote (Administrator) in the php Voting System
I will not talk much about the introduction to the voting system. This is not a graduation design. It mainly refers to the use of php to implement the voting system. Like other general systems, it is divided into two parts: one isAdministrator, One isCommon users.
The management part of the voting system is very simple. It provides two functions,Add and delete Voting
The key lies in the design of the database table. We plan to store a vote in this way. The voteparent table stores the voting title and description of whether the voting is deleted. The votechil.pdf table stores the sub-options and the number of votes for this vote.
I. Basic Objectives
First, the voting system is like this:
Click the three links to perform operations on relevant functions. This article focuses on the write administrator section, and the common user section uses jpgraph.
In the middle, there should be a logon system. This is not the focus. You can refer to my previous "php logon system and output viewer information" (click to open the link)
Click to add a voting option. The following page is displayed. You can add or delete voting options. A maximum of 10 voting options and at least two Avatar options are displayed. If the option is exceeded or not, a message is displayed:
The preview chart uses IE6, so the adding and deleting options are slow. After the Administrator fills in the voting information, the voting can be successfully added.
Before submitting the ticket, the Administrator will be asked whether to add the ticket to prevent misoperation. In fact, the system here should also use xajax to check whether the voting data exists. In addition, if any option is blank, the ticket should not be added, for details, refer to [php] to register the system and use Xajax to instantly verify whether the user name is occupied (click to open the link). This is not done here, because this article focuses on the core implementation of the voting system, these small details will not be deducted here.
Click the delete voting part of the voting system:
The delete button is displayed at the end of each vote. You can click the title of each vote to view this vote:
If you click the delete button, you will also be asked. If you click Cancel, nothing will happen. If you click OK, the voting will be successfully deleted:
You can clearly find that there are four votes before the deletion, and then there is only one vote after the deletion.
Ii. Basic Ideas
The voting system administrator does not have any new technology or database operations. First, the voteparent table structure is as follows:
Id is an auto-incrementing column, and title is the title of the voting column. For example, the above "I'm handsome and handsome" is used to store the description of the voting. If this is not done, the auto-incrementing column is not disconnected, the voting result can be viewed and deleted. The deletion mode is used to set the deletion bit isdel, which is displayed. This is the voting result with the deletion bit 0.
The votechildren table is as follows. id is an auto-incrementing column. text is used to store the description of each sub-option, count is used to store the number of votes for this sub-option, and parentid is used to store the vote for this sub-option. Although the table voteparent has reference constraints, you do not need to set a foreign key to avoid Operation troubles.
It is worth noting that after the two tables are created, remember to go to the table options tab and set the encoding of the two tables to UTF-8 to avoid garbled characters.
The directory structure of the site is as follows:
This document only describes the five pages of createvote.html, createvote.php, delvote.php, delvotehandle.php, and index.html.
Iii. Production Process
1、index.html
The first step is the most basic. There are only three chain-connected index.html. I won't talk about it here. There are only three a tags, and all the people who just learned html will do it. The Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2、createvote.html
Add a vote page. The entire add vote page processes the buttons of two self-owned js functions. It is a large form, and a hidden field is used to record how many options are available now,
The createvote. php page is added for the next step.
The following is a basic description. For javascript operations on web nodes, refer to my previous article "Examples of adding, deleting, modifying, and querying JavaScript For web nodes" (click to open the link)
Note that the added sub-option nodes will regularly use opt1, opt2, opt3 ...... This arrangement is to facilitate the following operations
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. createvote. php
Add the voting page. Note the following when inserting a database: insert voteparent first, then find the id of the record that just inserted voteparent, and insert the parentid of the votechil1_table. Note the following when looking for parentid, do not find the parentid by looking for the last insert record method, because if multiple administrators operate on the database concurrency, confusion may occur because there are Chinese characters, before the database operation, remember to add mysql_query ("set names utf8"); For more information, see the code:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
After adding the voting function, the Administrator deletes the voting function.
4. delvote. php
First, we will query all the voteparent's vote with a deleted bit not 1, and then sort them in descending order, because people want to see the newly added vote first, when a node is generated, set the deletion button id for each vote. This id is the voteparent id in the database for subsequent operations. You do not need to write any script for the deletion button, this id is uploaded to delvotehandle. php: Delete the processing page.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
</Script> the basic idea is that the page uses the div layout instead of the table, for details, refer to my previous "CSS" about div alignment and webpage layout "(click to open the link)
5. delvotehandle. php
Obtain the passed id and set the isdel deletion bit to 1 Based on the id.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The preceding section is the voting system administrator. The voting and voting deletion processes are added. session protection is also required for processing pages,
Do not enter the URL directly for access. You can refer to my previous "php + MySql login system and output viewer information function" (click to open the link)
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.