如何批量输入数据,并执行?
各位大神,是这样的,我要把若干数据逐组传递给adc.php执行;我知道一组一组的传可以用以下代码方式。但是如果我想传递很多组,不需要手工一组一组的输入,怎么办?
<script> <br />$(document).ready(function(){ <br />$("#submit").click(function(){ <br />var name=$("#name").val(); <br />var scores=$("#scores").val(); <br /> location.href=”adc.php?name=”+name+”&scores=”+scores; <br />} <br /></script>
例如,以下5组数据,如果分5次分别输入,上述程序可以,但是,有无可能我一次性将下表贴入文本框,然后程序自动识别,并逐组执行?谢谢大神。
小王 100
小张 121
小刘 541
张三 555
李四 410
回复讨论(解决方案)
思路应该是 数组 json传递 接收解析 foreach循环
可以啊 你把名字全部输出一个框中用个统一的分隔符分隔号 直接传递给php后explode一下就行 或者你在前端用string.splite()也行
比如你输入了: 小王 100 小张 121 小刘 541 张三 555 李四 410 都用空额分隔好
前端处理的话
var str = ' 小王 100 小张 121 小刘 541 张三 555 李四 410';var data = str.splite(" ");var urlparam = "?a=1";//多传一个没用的参数保持数据格式 方便下面循环for(var i = 0 ; i<data.length;1++){if(i%2 == 0){ urlparam += "&name[]="+data[i];}else{ urlparam += "&scores[]="+data[i]}} location.href="abc.php"+urlparam;
后台获得的是一个name数组和scores数组
或者你直接传递给后台
?data=小王 100 小张 121 小刘 541 张三 555 李四 410
后台explode()一下 根据上面类似的方法循环也可以
可以使用textarea保存,一行一个用户
然后,PHP根据换行来解释。
例如:
html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title> 提交 </title> </head> <body> <form name="form1" id="myform" method="post" action="server.php"> <p>数据:<textarea name="data"></textarea></p> <p><input type="submit" name="b1" onclick="fsubmit()" value="提交"></p> </form> </body></html>
server.php
<?php$data = $_POST['data'];$arr = explode("\r\n", $data);$result = array();for($i=0,$len=count($arr); $i<$len; $i++){ if($arr[$i]!=''){ list($name, $score) = explode(',', $arr[$i]); $result[] = array( 'name' => $name, 'score' => $score ); }}print_r($result);?>
在textarea中输入
小王,100
小张,121
小刘,541
张三,555
李四,410
提交后,PHP获取到
Array( [0] => Array ( [name] => 小王 [score] => 100 ) [1] => Array ( [name] => 小张 [score] => 121 ) [2] => Array ( [name] => 小刘 [score] => 541 ) [3] => Array ( [name] => 张三 [score] => 555 ) [4] => Array ( [name] => 李四 [score] => 410 ))
谢谢各位大神提供的思路和方法,我没有全部学会,但我大概学会了2楼的。谢谢大家。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

RESTAPI design principles include resource definition, URI design, HTTP method usage, status code usage, version control, and HATEOAS. 1. Resources should be represented by nouns and maintained at a hierarchy. 2. HTTP methods should conform to their semantics, such as GET is used to obtain resources. 3. The status code should be used correctly, such as 404 means that the resource does not exist. 4. Version control can be implemented through URI or header. 5. HATEOAS boots client operations through links in response.

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

The main function of anonymous classes in PHP is to create one-time objects. 1. Anonymous classes allow classes without names to be directly defined in the code, which is suitable for temporary requirements. 2. They can inherit classes or implement interfaces to increase flexibility. 3. Pay attention to performance and code readability when using it, and avoid repeatedly defining the same anonymous classes.
