我尝试使用 select 然后使用 insert 或 delete ... Insert And Delete 效果很好,但 Select 选项根本不起作用。我想使用 select 来显示表中的单行和行数。我有什么问题吗?
global $Itemid;
$user = JFactory::getUser();
$db2 = JFactory::getDBO();
$mediaid = $_POST["addMediaId"];
$delid = $_POST['delRow'];
$query = ' SELECT id'
. ' FROM #__mediamall_favourite_media'
. ' WHERE mediaid = "'.$mediaid.'" AND userid = "'.$user->id.'"';
$db2->setQuery($query);
$db2->query();
$rows = $db2->getNumRows();
$result = $db2->loadRowList();
$del = $db2->loadObject();
if(isset($_POST["submitCheck"]) && $_POST["submitCheck"] == "1") {
$query = " INSERT INTO `#__mediamall_favourite_media` (`id`, `userid`, `mediaid`) VALUES (NULL,'".$user->id."','".$mediaid."')";
}
elseif(isset($_POST["submitCheck"]) && $_POST["submitCheck"] == "0") {
$query = " DELETE FROM `#__mediamall_favourite_media` WHERE `id` = '".$delid."' ";
}
if($query) {
$db2->setQuery($query);
$db2->query();
}