我有主表到子表,需要一个解决方案,以低于条件呈现它。
function deleteSubmission($conn,$submission_id)
{
$query = "DELETE FROM submissions WHERE submission_id=:submission_id";
$stmt = $conn->prepare($query);
$stmt->bindValue(':submission_id',$submission_id);
$affected_rows = $stmt->execute();
if($affected_rows==1)
{
//echo $affected_rows;
echo ($affected_rows) ? "true" : "false";
echo " working ";
return true;
}else{
//echo $affected_rows;
echo ($affected_rows) ? "true" : "false";
echo " not working ";
return false;
}
}
孩子的产品是Master的外键。
在模板中,我将提取主字段(在for循环中),但如果在子节点中存在price和customfields,那么我需要使用product关系获取子对象,否则从master表中填充这些对象。
这里出现了混乱,
//they didn't submit the form
if(!isset($_POST["deleteSubmissionsBtn"]))
{
header("Location:all-submissions-delete.php");
exit;
}
$msg;
//validate
if(isset($_POST['submissions']))
{
$submissions=$_POST['submissions'];
$conn=getConn();
$count=0;
foreach ($submissions as $submission_id)
{
if(deleteSubmission($conn,$submission_id))
{
$count++;
}
else{
echo "we got an error <br>";
}
}
print_r($submissions);
//echo $submission_id;
$conn=NULL;
$msg="Successfully deleted $count submissions";
}else{
$msg="You need to select some submissions to delete";
}
include("views/delete-feedback-view.php")
?>
请建议。
修改
echo "<form action='delete-submissions.php' method='POST'>";
foreach($allSubmissions as $submission)
{
echo "<div>";
echo "<label>".$submission->title."</label>";
echo "<input type='checkbox' value='".$submission->submission_id."' name='submissions[]'/>";
echo "</div>";
}
echo "<input type='submit' name='deleteSubmissionsBtn' value='delete submissions'>";
echo "</form>";
子表可能包含也可能没有给定供应商和pdctg
的所有主行