gpt4 book ai didi

php - 如何将多个ID传递到jobCart页面?

转载 作者:行者123 更新时间:2023-11-29 21:35:22 25 4
gpt4 key购买 nike

我有一个职位列表页面,显示所有职位,每个职位旁边都有复选框,页面底部有一个“添加”按钮,可将其添加到 JobCart.php

老实说,我不知道如何将多个记录 ID 或单个 ID 传递给 jobCart.php我希望当用户单击“添加”按钮时将所有选定的 ID 传递给 jobCart.php请帮助我

            <?php
// adding JobsLists.php to this page to interact witht it.
require ("../JobsLists.php");

//Connect to DB
//include_once("Project/CIEconn.php");
$mysqlCON= mysqli_connect("localhost", "root", "","CIE") or die(mysqli_connect_error());
mysqli_select_db($mysqlCON,'CIE') or die ("no database");

$ID = isset($_POST['Id']); // 1 2

if( isset($_POST['pick']) ){

if( empty($ID) || $ID == 0 ){
echo"<h4> please choose something to move to your job list </h4>";
}else{

// Code here ..
// here here ONLY for TEST to check if I can interact eith jobLists.php
addJob();

// to get all ID from each selected job
$impid = implode("' , '" , $_POST['Id']);


}

}





$sqlCommand = "SELECT * FROM Fiscal WHERE NoStudent > '0' ";
$result = mysqli_query($mysqlCON,$sqlCommand) or die(mysqli_error($mysqlCON));


echo '
<form action= "Fiscal.php" method = "post">
<table width ="100%" cellpadding ="4" border="1" >

<tr>
<th>Check </th>
<th>Jobs Name</th>
<th>Description</th>
<th> No Students needed</th>
<th>Due Date</th>
</tr>';

while ($row = mysqli_fetch_array($result) ){

// name = 'Id[]'
echo "<tr>

<td> <input type='checkbox' name='Id[]' value='". $row['Id'] ."' /> </td>


<td> ". $row['JobName'] ." </td>
<td> ". $row['Description'] ." </td>
<td> ". $row['NoStudent'] . "</td>
<td>". $row['DueDate'] ." </td>
</tr>";


}

echo '
</table>
<br/>

<div align="center">
<input type="submit" name="pick" value="Add Job" />

<input type="reset" value="Clear Marks" />
</div>

</form>

';

?>

<html>
<head><title> Fiscal </title></head>
<br>
<body>
</body>
</html>

最佳答案

首先,在页面的最顶部启动 session ,如下所示:

<?php
session_start();
?>

在表单处理期间,将 $_POST['Id'] 数组存储到 $_SESSION 超全局变量,并使用 header( 将用户重定向到 jobCart.php 页面) ) 函数。

还有一件事,$_POST['Id'] 将是一个数组,因此请使用 count() 函数来查看它是否为空。所以你的代码应该是这样的:

// your code

if(isset($_POST['pick'])){

if(count($_POST['Id'])){
// store `$_POST['Id']` array to `$_SESSION` superglobal
$_SESSION['ids'] = $_POST['Id'];

// redirect the user to jobCart.php page
header("Location: jobCart.php");
exit();
}

}

// your code

在 jobCart.php 中你可以做这样的事情:

$impid = implode("','" , $_SESSION['ids']);

// rest of your code

关于php - 如何将多个ID传递到jobCart页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34965327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com