我正在尝试将treatmentItem id传递给deleteTreat链接,以便将数据库中的可见性设置为0,但我不确定如何传递我想要的部分的id。
HTML视图
<div class="treatmentItem" id="1">
<div class="editName edit_text"> name</div>
<div class="deleteTreat"><a href="#"> Delete </a></div>
<div class="editPrice edit_text">price</div>
<div class="editBlurb edit_text">blurb</div>
<div class="hr"></div>
PHP查看:
public function renderAdminCategory($iCatID){ // Function to View Treatment Content
$category = new Category();
$category->load($iCatID);
$CategoryOutput = '';
$CategoryOutput .='<div class="clear"></div><!--end of clear-->';
$CategoryOutput .='<div id="treatmentsContent"><!--Displaying Treatments from selected Treatment category -->';
$aSubCategories = $category->getSubCategories(); // This stores information from getSubCategories inside aSubCategories
foreach($aSubCategories as $subID=>$oSubCat){ // The Category
$name = $oSubCat->getSubCatName(); // This retrieves the Name out of the SubCatObject
$CategoryOutput .='<!--';
$CategoryOutput .=$name;
$CategoryOutput .='--><h2 class="categoryName">'."\n";
$CategoryOutput .=$name.'</h2>'."\n";
$CategoryOutput .='<div class="break"></div>'."\n";
$treatments = $oSubCat->getTreatments();
foreach($treatments as $treatmentID=>$oTreatment){ // The Treatment
$name = $oTreatment->getTreatmentName(); // Getting the TreatmentName from the treatment object - oTreatment
$price = $oTreatment->getTreatmentPrice();
$blurb = $oTreatment->getTreatmentBlurb();
$id = $oTreatment->getTreatmentID();
//$subCatId = $oTreatment->getSubID();
$delete = new Treatment();
$delete->deleteTreatment($id);
//$CategoryOutput .='<div class="treatmentClear"</div>';
$CategoryOutput .='<div class="treatmentItem" id="'.$id.'">'."\n";
$CategoryOutput .='<div class="editName edit_text">'.$name.'</div>'."\n";
$CategoryOutput .='<div class="deleteTreat"><a href="delete.php?id='. $row[ID] .' "> Delete </a></div>';
$CategoryOutput .='<div class="editPrice edit_text">'.$price.'</div>'."\n";
$CategoryOutput .='<div class="editBlurb edit_text">'.str_replace("\n",'<br/>',htmlentities($blurb)).'</div>'."\n";
$CategoryOutput .='<div class="hr"></div>'."\n";
$CategoryOutput .='</div><!-- end of treatmentItem-->';
}
}
//'.$delete->deleteTreatment($id).'
$CategoryOutput .='</div><!--end of treatmentscontent-->';
return $CategoryOutput;
}
删除功能
public function deleteTreatment($iTreatmentID){
global $database;
$sQuery = "UPDATE treatments SET visible=0 WHERE treatmentID=".$iTreatmentID;
$resultTreatment = $database->query($sQuery);
echo "Successfully Deleted";
}
答案 0 :(得分:0)
$CategoryOutput .='<div class="deleteTreat"><a href="delete.php?id='. $id .' "> Delete </a></div>';
不是$row[ID]
而是$id
另外
$delete = new Treatment();
$delete->deleteTreatment($id);
即使将其删除或设置为零,仍会显示您的治疗方法。你需要在获得列表之前调用它(因为我假设$oSubCat->getTreatments();
从数据库中获取可见的所有内容)
$delete = new Treatment();
$delete->deleteTreatment($id);
//then you get avalable treatmants
$treatments = $oSubCat->getTreatments();`
现在,我假设delete.php调用显示处理的函数
换句话说:您的链接必须是显示数据并调用renderAdminCategory($ catID)的同一文件。所以你必须在链接中解析AND $ icatID。就这样
public function renderAdminCategory($iCatID){ // Function to View Treatment Content
$category = new Category();
$category->load($iCatID);
$CategoryOutput = '';
$CategoryOutput .='<div class="clear"></div><!--end of clear-->';
$CategoryOutput .='<div id="treatmentsContent"><!--Displaying Treatments from selected Treatment category -->';
$aSubCategories = $category->getSubCategories(); // This stores information from getSubCategories inside aSubCategories
foreach($aSubCategories as $subID=>$oSubCat){ // The Category
$name = $oSubCat->getSubCatName(); // This retrieves the Name out of the SubCatObject
$CategoryOutput .='<!--';
$CategoryOutput .=$name;
$CategoryOutput .='--><h2 class="categoryName">'."\n";
$CategoryOutput .=$name.'</h2>'."\n";
$CategoryOutput .='<div class="break"></div>'."\n";
if(isset($_REQUEST['id'])
{
$delete = new Treatment();
$delete->deleteTreatment($_REQUEST['id']); //get the request parameter
}
//then you get avalable treatmants
$treatments = $oSubCat->getTreatments();
foreach($treatments as $treatmentID=>$oTreatment){ // The Treatment
$name = $oTreatment->getTreatmentName(); // Getting the TreatmentName from the treatment object - oTreatment
$price = $oTreatment->getTreatmentPrice();
$blurb = $oTreatment->getTreatmentBlurb();
$id = $oTreatment->getTreatmentID();
//$subCatId = $oTreatment->getSubID();
$delete = new Treatment();
$delete->deleteTreatment($id);
//$CategoryOutput .='<div class="treatmentClear"</div>';
$CategoryOutput .='<div class="treatmentItem" id="'.$id.'">'."\n";
$CategoryOutput .='<div class="editName edit_text">'.$name.'</div>'."\n";
$CategoryOutput .='<div class="deleteTreat"><a href="renderAdminCategory.php?id='. $id .'&catID='.$iCatID.' "> Delete </a></div>';
//we added catID and this link will point to the file that is displayinf the data and callign this function
$CategoryOutput .='<div class="editPrice edit_text">'.$price.'</div>'."\n";
$CategoryOutput .='<div class="editBlurb edit_text">'.str_replace("\n",'<br/>',htmlentities($blurb)).'</div>'."\n";
$CategoryOutput .='<div class="hr"></div>'."\n";
$CategoryOutput .='</div><!-- end of treatmentItem-->';
}
}
//'.$delete->deleteTreatment($id).'
$CategoryOutput .='</div><!--end of treatmentscontent-->';
return $CategoryOutput;
}
还要确保在更新功能中转义值
$sQuery = "UPDATE treatments SET visible=0 WHERE treatmentID=".mysql_real_escape_string($iTreatmentID);