简体   繁体   English

将 Javascript 数组转换为 PHP 数组或将其传递给 PHP 文件

[英]Converting Javascript array to PHP array or passing it to a PHP file

I am working on a movie ticket booking database using Mysql and PHP.I've done the frontend part using HTML,CSS.我正在使用 Mysql 和 PHP 处理电影票预订数据库。我已经使用 HTML,Z28C5DDB93EDZ205DBB1CED00381AA4Z,Z285DFB93EDZ2058204 完成了前端部分The below code is to change the image of the selected seat.The Available seats are shown in red,the booked ones are white.以下代码用于更改所选座位的图像。可用座位显示为红色,已预订的座位显示为白色。 When the user clicks on a red image it'll turn to black,to show that the seat has been selected.But i need the list of seats which are selected by the user,in other words, i want the name of the seats,the user have booked.All seats have a seat name associated with the image.I'm stuck at this point,the seat names are stored in "seats" array of javascript.当用户点击红色图像时,它会变成黑色,表明座位已被选中。但我需要用户选择的座位列表,换句话说,我想要座位的名称,用户已预订。所有座位都有一个与图像关联的座位名称。我被困在这一点上,座位名称存储在 javascript 的“座位”数组中。 But i need this data into php to update the same into my database.I've no knowledge on JSON,AJAX.etc.但我需要将这些数据导入 php 以将其更新到我的数据库中。我对 JSON、AJAX.等一无所知。 please help me resolve this.请帮我解决这个问题。 Thank you.谢谢你。

<script > var seats=[]; function sample(id){ document.getElementById(id).src="https://image.flaticon.com/icons/png/512/24/24868.png"; seats.push(id); alert(seats); } </script>

As I understand, once image for seat is clicked you are storing that in seats array & marking that image as black/selected.据我了解,一旦单击座位图像,您就会将其存储在座位阵列中并将该图像标记为黑色/选中。

Now you must have some Continue/Proceed/Book button to finalize selected seats.现在您必须有一些继续/继续/预订按钮来完成选定的座位。

Now add a onclick function to that button & in that function you need to create an ajax request to PHP Now add a onclick function to that button & in that function you need to create an ajax request to PHP

to pass seats array with Ajax refer here使用 Ajax 传递席位数组,请参阅此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM