Emp_ID
従業員 ID ( ) をschedule
テーブルに 30 回入力しようとしています。従業員 ID がemployee
テーブルから取得されています。最初のループでは機能しますが、2 番目のループでは機能しません。私が得るエラーは
「致命的なエラー: 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 . ']');
}
}
}
?>