由于某些原因,我的for循环不是从看起来的外观开始。我通过在其中放置一个echo语句测试它并且它没有显示所以必须有一些错误,也许我的语法,但是看了几个小时后我看不到它。
感谢您的时间。
echo $completedstaffrows; // value of 5
echo $completedeventrows; //value of 4
echo "<br/>";
//Staff
//For loop to enter the correct amount of rows as entered in the form
for ($i=0; $i > $completedstaffrows; $i++)
{
//Data not inserted into Staff table, FK given from dropdown on form to insert in linking table
$staffdata = array
(
'staff_id' => $this->input->post ('staff'.$i),
'procedure_id' => $procedurefk,
'quantity' => $this->input->post ('staff_quantity'.$i),
'quantity_sterilised' => NULL, //not implemented yet
);
$inserthumanresource = $this->db->insert ('hr', $staffdata);
echo "hello world"; // to test if for loop working
}
//Events
//For loop to enter all events rows completed by user
for ($i=0; $i > $completedeventrows; $i++)
{
//First input into "Medical Supplies" table
$medsupplies = array
(
'name' => $this->input->post ('supplies'.$i),
'manufacturer' => "Bruce Industries" //To be implemented
);
//Insert data into table
$insertmeds = $this->db->insert ('med_item', $insertmeds);
//Get med supplies foreign key for linking table
$medsuppliesfk = $this->db->insert_id();
//Then input into table "Event"
$eventdata = array
(
'time' => $this->input->post ('time'.$i),
'event' => $this->input->post ('event'.$i),
'success' => $this->input->post ('success'.$i),
'comment' => $this->input->post ('comment'.$i),
'procedure_id' => $procedurefk
);
//Insert
$insertevent = $this->db->insert ('procedure_event', $eventdata);
//Get event fk for linking table
$eventfk = $this->db->insert_id();
//Linking table "Resources"
$resourcedata = array
(
'event_id' => $eventfk,
'medical_item_id' => $medsuppliesfk,
'quantity' => NULL, //Not implemented yet
'unit' => NULL
);
$insertresource = $this->db->insert ('resources', $resourcedata);
答案 0 :(得分:4)
for ($i=0; $i > $completedstaffrows; $i++)
应阅读:
for ($i=0; $i < $completedstaffrows; $i++)
或者也许:
for ($i=0; $i <= $completedstaffrows; $i++)
答案 1 :(得分:3)
变化
for ($i=0; $i > $completedstaffrows; $i++)
到
for ($i=0; $i < $completedstaffrows; $i++)
你想迭代,而我比变量少,而不是更多。
答案 2 :(得分:3)
您的操作员不正确。将>
切换为<
。
答案 3 :(得分:3)
您只是在i
大于$completedstaffrows
时进行循环播放等。将>
更改为<
s。
答案 4 :(得分:2)
$i=0; $i < $completedstaffrows; $i++
^^^^^
答案 5 :(得分:2)
你写的那个$ completedstaffrows = 5并且你初始化$ i = 0,在你写“$ i&gt; $ completedstaffrows”的循环中,第一次运行评估为0&gt; 5恰好是假的。这就是为什么它不能进入循环。所以替换“&gt;”用“&lt;”解决问题。