Many Many 테이블에서 작업 중이며 레코드를 가져올 수없는 문제가 해결되었습니다. 이제는 필요할 때 레코드를 삭제하려고합니다.관련된 테이블에서 레코드 제거하기 PHP
나는 아이들이 사건과 관련 될 수있는 사이트를 가지고있다. 아이가 실수로 추가 된 경우 나는 아이를 제거 할 수 있기를 원합니다. 다음과 같이 확인란을 통해 추가됩니다.
<input type="checkbox" name="eventChildren[]" id="childId_12" />
<input type="checkbox" name="eventChildren[]" id="childId_13" />
<input type="checkbox" name="eventChildren[]" id="childId_14" />
나는 이미 자식이 추가 된 경우 미리 선택되는 여러 개의 확인란이 있습니다.
DB:
- children
- events
- eventChildren
나는 레코드를 저장
내가 내eventChildren
테이블에 중복을 추가하지 마십시오 확인하기 위해 검사를하고 있어요 :
나는 세 개의 테이블 (이 관련이 있는지 확실하지 않습니다)가 있습니다. 레코드가 이미 데이터베이스에 있지만 폼에서 제출되지 않은 경우 자식이 목록에서 제거되는 경우 ...이 하위 집합을 잡는 방법을 파악할 수 없습니다.
예제 코드 :
폼이 나는eventChildren
테이블
eventId
경기에서 모든 기록을 잡고 수익을 얻을 제출
// $eventChildren comes from the form above name="eventChildren[]"
// $eventId is passed into the function
$currentChildren = $this->eventChildren->GetEventChildren(array('eventId' => $eventId));
// Loop through all submitted children
foreach ($eventChildren as $childId)
{
// Loop through all existing children
foreach ($currentChildren as $currChild)
{
// If the child ID's do not match then it's a new record
if ($currChild->childId != $childId)
{
$this->eventChildren->AddEventChildren(array(
'eventId' => $eventId,
'childId' => $childId
));
}
}
}
.
eventChildren (return)
- [0]
eventChildrenId => 1
childId => 12
eventId => 4
- [1]
eventChildrenId => 2
childId => 13
eventId => 4
- [2]
eventChildrenId => 3
childId => 14
eventId => 4
submittedChildren
- [0] => 12
- [1] => 13
어떻게 기록 eventChildrenId = 3
를 제거 submittedChildren
배열을 기반으로 말할 수 있습니까?
나는 이것이 의미가 있기를 바랍니다. :)
더 좋은 방법은 무엇입니까? 내가 사용하고있는 현재의 방법은 ID가 8과 10 인 두 ID가 있기 때문에 실제로 작동하지 않습니다. 10이 8 일 때 8은 동일하지 않으므로 새 레코드를 추가하고 그 반대의 경우도 마찬가지입니다. – Seth