Home > Article > Backend Development > Processing of multiple selections with PHP and javascript_PHP tutorial
We often need to allow users to make multiple choices for processing, such as allowing users to select multiple items on a list and then delete the selected items, etc. Today I will give an example to illustrate how PHP and JavaScript handle multiple selections respectively. What we are working on today is a voting system to vote for items in the itemtable table of the MySQL database, and each IP can only cast two votes.
The table itemtable is created through the following MySQL statement:
CREATE TABLE `itemtable` (
`id` TINYINT( 4 ) NOT NULL AUTO_INCREMENT,
`name` VARCHAR( 50 ) NOT NULL ,
`votes` SMALLINT( 6 ) NOT NULL ,
PRIMARY KEY ( `id` )
);
The field "name" is the name of the list item, and "votes" is the number of votes received. We also need to create a table "voteiptable" to record the IP of voting users:
CREATE TABLE `voteiptable` (
`id` SMALLINT( 6 ) NOT NULL ,
`voteip` VARCHAR( 15 ) NOT NULL,
PRIMARY KEY ( `id` )
);
Next we write the file "multivote.php". Today we will use a database class file "dbclass.php".
We can find that there are many similarities in the processing of multiple selections by client-side JavaScript and server-side PHP, but of course there are also differences. This is a relatively classic multi-option processing program. It would be simpler if the user's options are not limited.