gpt4 book ai didi

php - 显示上次插入数据的数据时出现问题

转载 作者:行者123 更新时间:2023-11-30 23:41:39 24 4
gpt4 key购买 nike

我正在设计员工轮值表……有三个表 Staff(员工详细信息)、Event(事件详细信息)和 Job(JobId、JobDate、EventId (fk)、StaffId (fk))。我需要显示最后插入的工作详细信息和员工姓名。我已经花了几个小时了,却一无所获。我在这里先向您的帮助表示感谢。我的代码如下:

$eventId = $_POST['eventid'];
$selectBox = $_POST['selectbox'];
$timePeriod = $_POST['time'];
$selectedDate = $_POST['date'];
$count = count($selectBox);

echo "<fieldset><center>";
echo "<form name=submit action='' method=post>";

//display the selected event
$eventsql = "SELECT EventName FROM Event WHERE EventId= ".$eventId;
$result = mysql_query($eventsql);

while ($eventarray = mysql_fetch_array($result))
{
$eventName = $eventarray['EventName'];
echo "<h3><font color=red>".$eventName." </font></h3>";
}

//constructing the staff selection
if (empty($selectBox))
{
echo "<p>You didn't select any member of staff to be assigned.";
echo "<p><input type='button' value='Go Back' onClick='history.go(-1)'>";
} else
{
echo "<p> You selected ".$count. " staff for this show.";

for ($i=0;$i<$count;$i++)
{
$selectId[$i] = $selectBox[$i];

//insert the details into the Job table in the database
$insertJob = "INSERT INTO Job (JobDate, TimePeriod, EventId, StaffId)
VALUES ('".$selectedDate."', '".$timePeriod."', ".$eventId.",
".$selectId[$i].")";
$exeinsertJob = mysql_query($insertJob) or die (mysql_error());


}
}

//display the staff details (last inserted) assigned to the job
$insertedlist = "SELECT Staff.LastName, Staff.FirstName, Job.JobDate, Job.TimePeriod
FROM Staff, Job
WHERE Job.StaffId = Staff.StaffId
AND Job.JobDate = ".$selectedDate;
$exeinsertedlist = mysql_query($insertedlist) or die (mysql_error());

if ($exeinsertedlist)
{
echo "<p><table cellspacing='1' cellpadding='3'>";
echo "<tr><th>Last Name</th><th>First Name </th><th>Date</th><th>Hours</th></tr>";

while ($joblistarray = mysql_fetch_array($exeinsertedlist))
{
echo "<tr><td align=center>".$joblistarray['LastName']."
</td><td align=center>".$joblistarray['FirstName']."
</td><td align=center>".$joblistarray['JobDate']."
</td><td align=center>".$joblistarray['TimePeriod']."</td></tr>";
}

echo "</table>";

echo "<h3><a href=AssignStaff.php>Add More Staff?</a></h3>";
}
else {
echo "The Job list can not be displayed at this time. Try again.";
echo "<p><input type='button' value='Go Back' onClick='history.go(-1)'>";
}




echo "</center>";
echo "</fieldset>";
echo "</form>";

最佳答案

你有 mysql_inserted_id 来获取最后插入的作业 ID。

http://php.net/manual/en/function.mysql-insert-id.php

关于php - 显示上次插入数据的数据时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2551937/

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