search
Homephp教程php手册PHP与&#106avascript对多项选择的处理

PHP与&#106avascript对多项选择的处理

Jun 13, 2016 pm 12:45 PM
ampphpanddeal withrightusofwantconductchoose

  我们经常要给用户作出多项选择进行处理,例如允许用户对列表项选择多项后删除选定项等。今天举个例子说明PHP和JavaScript分别是怎样处理多项选择的。今天我们做的是一个投票系统,对MySQL数据库itemtable表里的项目进行投票,且每个别IP能且只能投两票。



  表itemtable是通过以下MySQL语句建立的:

CREATE TABLE `itemtable` (
`id` TINYINT( 4 ) NOT NULL AUTO_INCREMENT,
`name` VARCHAR( 50 ) NOT NULL ,
`votes` SMALLINT( 6 ) NOT NULL ,
PRIMARY KEY ( `id` )
);

其中字段“name”是列表项目名,“votes”是所得票数。我们还要建立一个表“voteiptable”来记录投票用户的IP:

CREATE TABLE `voteiptable` (
`id` SMALLINT( 6 ) NOT NULL ,
`voteip` VARCHAR( 15 ) NOT NULL,
PRIMARY KEY ( `id` )
);

下面我们编写文件“multivote.php”,今天我们要用到一个数据库类文件“dbclass.php”.




  我们可以发现,客户端的JavaScript和服务器端的PHP对多项选择的处理有很多相似之处,当然也有不同。这是比较经典的多选项处理的程序,如果不限定用户的选项的话就更简单了。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment