PHP Front-end passed the string in the background to parse the array at the same time batch add

Source: Internet
Author: User
Tags explode rtrim

Front-end page code gets multiple lines of obj

function Addbedtype () {

var obj = document.getelementsbyname (' type_name ');

var Duoxuan = ';

for (var i = 0; i < obj.length; i++) {

Duoxuan + = Obj[i].value + ', ';//If selected, add value to the variable Duoxuan

alert (Duoxuan);}

if (Duoxuan.length < 1) {

Alert (' Please add at least one item! ‘); return 0;

} else {

if (! ( Confirm (' Are you sure you want to add? ‘))) {

return false; }

}

$.ajax ({

URL: ' {: U ("Home/gat/addbedtype")} ',

Type: ' Post ',

Data: {"Duoxuan": duoxuan},//"Duoxaun" value is a string, such as {1, 2,} This type, need to parse out in the background

Success:function (data) {

Window.location.href = "/home/gat/bed"; }

}

)

}

Background Code Operations Database

Public Function Addbedtype () {
$data = Array ();
$dump = $this->seria ();
$whe [' ubid '] = $dump [' ubid '];
$whe [' add_time '] = time ();

The following is the action to parse the front-end parameters, changing the string into an array.

RTrim () is used to remove the string {"1, 2,"} to the right of the "," comma.

Explode () Changes {"" "} to an array
$x = $_post[' Duoxuan ');
$data = Explode (', ', RTrim ($x, ', '));
foreach ($data as $v) {
$whe [' type_name '] = $v;
M (' Bed_type ')->add ($whe);
}

}

PHP Front-end passed the string in the background to parse the array at the same time batch add

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.