我試圖在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 –