我试图在schedule
表中输入员工编号(Emp_ID
)30次。员工ID正从employee
表中拉出。它将在第一个循环中工作,但在第二个循环中休息。我得到的错误是如何多次插入结果集?
"Fatal error: Call to a member function fetch_assoc() on a non-object in C:\wamp\www\server\roster\dates.php on line 110"
线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 . ']');
}
}
}
?>
不仅你在回答这个问题时变得很快,你已经死了!非常感谢! –
我希望我一样快:P –