我正在尝试将员工 ID ( Emp_ID
) 输入schedule
表 30 次。正在从employee
表中提取员工 ID。它将在第一个循环上工作,但在第二个循环上中断。我得到的错误是
“致命错误:在第 110 行的 C:\wamp\www\server\roster\dates.php 中的非对象上调用成员函数 fetch_assoc()”
第 110 行是while
循环。我只能假设这种情况正在发生,因为结果集正在被清空,但我不知道如何解决它。
<?php
//Select all of the current Employees by ID number
$sql = ("SELECT Emp_ID FROM employee");
//Run a check on the query to make sure it worked.
//if it failed then print the error.
if(!$result = $mysqli->query($sql))
{
die('There was an error getting the Emp_ID from the employee table [' . $mysqli->error . ']');
}
//Loop through the results...
while($row = $result->fetch_assoc())
{
//...and for each employee ID, enter it into the table 30 times.
for($i = 1; $i <= 30; $i++ )
{
$sql = ("INSERT INTO schedule (Emp_ID) VALUES ('" . $row['Emp_ID'] . "')");
//Run a check on the query to make sure it worked.
//if it failed then print the error.
if(!$result = $mysqli->query($sql))
{
die('There was an error inserting the Emp_ID into the schedule [' . $mysqli->error . ']');
}
}
}
?>