如何批量输入数据,并执行?
各位大神,是这样的,我要把若干数据逐组传递给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

AI Hentai Generator
Generate AI Hentai for free.

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

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
