所以我想在每次用户点击btnChangeCat
按钮时运行一个功能......我遇到了麻烦,我真的不确定如何让它工作!
我尝试运行showCategory($_POST['chkCat'], 1)[0];
并在用户点击btnChangeCat
按钮时将已复选的复选框数组传递给它。我不知道为什么这不起作用?
我在各处搜索了一个WORKING解决方案,但在将值传递给函数时找不到一个可行的方法!
$showVideos = showCategory($categories, 1)[0];
$rowLength = showCategory($categories, 1)[3];
$likes = showCategory($categories, 1)[1];
$dislikes = showCategory($categories, 1)[2];
?>
<main>
<div class='controller-wrap'>
<div class='content-wrap'>
<h3>Category: </h3>hp
<form action='most-liked.php' method='post'>
<?php
$allCategories = ["All", "Sport", "Automotive", "Comedy", "Misc", "Surfing"];
$htmlOutput = "";
$i=0;
for($i;$i<sizeof($allCategories);$i++)
{
if($allCategories[$i] == "Surfing"){
$htmlOutput .= "<input selected='selected' type='checkbox' name='chkCat[]' value='".$allCategories[$i]."'/>";
}
else{
$htmlOutput .= "<input type='checkbox' name='chkCat[]' value='".$allCategories[$i]."'/>";
}
}
echo $htmlOutput;
?>
</form>
<br />
if(isset($_POST['chkCat'])){
if(is_array($_POST['chkCat'])) {
foreach($_POST['chkCat'] as $value){
echo $value;
}
}else{
$value = $_POST['chkCat'];
echo $value;
}
// showCategory($_POST['chkCat'], 1)[0];
}
isset($_POST['btnChangeCat'])){
// //How can I run this function with the array of CHECKBOXES??
showCategory($_POST['chkCat'], 1)[0];
}
?>
<input type='submit' value='CHANGE CATEGORIES' class='btnlike btnLike' name='btnChangeCat'/>
</div>
</main>