我正在制作一个关于在线考试的项目,其中管理员可以添加测试,之后它将在div中显示。在div中,它将显示所有选定测试的列表,因此,他可以通过简单地单击十字标记来删除任何测试。所以,我陷入了这样一个过程,如果我删除任何测试,之后我提交了一个表格然后它显示我所有的测试,包括删除的测试。以下是我的代码:
<?php
if(isset($_POST['addTest']))
{
echo "<br>";
echo "SELECTED TEST LIST";
echo "<br>";
echo '<div style="backfround:white;padding:5px;border:2px solid;overflow:scroll;height:100px;">';
$fruitList = implode(', ', $_POST['jdb']);
$jdStore = explode(',',$fruitList);
$jdValueStore = "";
for($i=0;$i<count($jdStore);$i++)
{
$testShowState = "select testId, testName from test where testId= '$jdStore[$i]'";
$testShowQuery = mysql_query($testShowState);
$testShowFetch = mysql_fetch_array($testShowQuery);
echo $jdValueStore[] = "<div class='divClass'>
<p>".$testShowFetch['testName']."</p>
<img src='images/deletebttn.gif' alt='delete' class='deleteDiv' />
</div>";
}
echo '</div>';
}
$jdTotal = serialize($jdValueStore);
$encoded = htmlentities($jdTotal);
?>
<input type="hidden" name="jdStoreValue" value="<?php echo $encoded; ?>">
<input type="submit" class="button add" value="Save" style="width:auto;" id="addSave" onclick="myAddSave()" name="myAddSave" >
在我获取值的页面上:
$jdStoreValue = unserialize($_POST['jdStoreValue']);
for($i=0;$i<count($jdStoreValue);$i++)
{
echo $jdStoreValue[$i];
}
它向我展示了所有的测试。我不想删除测试。
答案 0 :(得分:0)
您应该删除序列化代码。
if(isset($_POST['addTest']))
{
echo "<br>";
echo "SELECTED TEST LIST";
echo "<br>";
echo '<div style="backfround:white;padding:5px;border:2px solid;overflow:scroll;height:100px;">';
$fruitList = implode(', ', $_POST['jdb']);
$jdStore = explode(',',$fruitList);
$jdValueStore = "";
for($i=0;$i<count($jdStore);$i++)
{
$testShowState = "select testId, testName from test where testId= '$jdStore[$i]'";
$testShowQuery = mysql_query($testShowState);
$testShowFetch = mysql_fetch_array($testShowQuery);
echo '<input type="hidden" name="fruitList[]" value="'.$testShowFetch['testId'].'" />';
echo $jdValueStore[] = "<div class='divClass'>
<p>".$testShowFetch['testName']."</p>
<img src='images/deletebttn.gif' alt='delete' class='deleteDiv' />
</div>";
}
echo '</div>';
}
<input type="submit" class="button add" value="Save" style="width:auto;" id="addSave" onclick="myAddSave()" name="myAddSave" >
答案 1 :(得分:0)
将jquery onclick事件绑定到交叉按钮,这将减少删除检查的次数,同时更新隐藏字段。