从管理员中删除数据库中的行

时间:2014-02-18 13:59:51

标签: database joomla delete-row corresponding-records

我有一个组件,我想在管理员中添加一个删除按钮,但我无法使其工作。这是我的代码(评论的所有行,我试过它们):

`<?php `
`$db = JFactory::getDBO();`



`$query = $db->getQuery(true);`

/* ----------------- STERGERE -----------------------*/

    `if(isset($_GET['delete']))
    { $query->delete('*');

      $query->from('roy_testimonial');

      $query->where('testimonial_id = "'.$_GET['delete'].'"'); 

      $db->setQuery($query);

    }`
/* ----------------- END STERGERE -----------------------*/
/*-------------- AFISARE ------------------ */

`$query->select('*');`

`$query->from('roy_testimonial');`


`$db->setQuery($query);`

`$options = $db->loadAssocList();`

`foreach($options as $row) {

    $firstname = htmlentities($row['firstname']);

    $lastname  = htmlentities($row['lastname']);

    $city  = htmlentities($row['city']);

    $state  = htmlentities($row['state']);

    $mesaj  = htmlentities($row['user_mesaj']);

    $purchase  = htmlentities($row['your_purchase']);

    $sales  = htmlentities($row['sales']);

    $financing  = htmlentities($row['financing']);

    $service  = htmlentities($row['service']);

    $parts  = htmlentities($row['parts']);

    $accesories  = htmlentities($row['accesories']);

    $id = $row['testimonial_id'];`

/* ----------------- END AFISARE -----------------------*/


`?>`

`<div style="float:left;width:600px;">`

`<h2 style="color:#015CB7;"><?php echo $id; ?>) <?php echo $firstname;?> <?php echo $lastname;?>`

`<font style="color:#000;font-size:14px;">( <?php echo $city;echo ','; echo $state;?> )</font></h2>`

`<p>`

`<font style="font-size:14px;font-weight:bold;">Mesaj:</font>  <?php echo $mesaj; ?></p>`

`</div>`

`<div style="float:left;width:300px;">`

<!-- RATING -->

`<h2 style="color:#015CB7">Rating</h2>`

`Your Purchase: <?php echo $purchase; ?> <br/>`

`Sales: <?php echo $sales; ?> <br/>`

`Financing and Insurance: <?php echo $financing; ?> <br/>`

`Service: <?php echo $service; ?> <br/>`

`Parts: <?php echo $parts; ?> <br/>`

`Accesories: <?php echo $accesories; ?> <br/>`

`</div>`

`<div style="float:right;width:300px;">`

`<a href="?delete=<?=$id;?>">Sterge</a>`
`</div>`

`<div style="clear:both;"></div>`



`<?php } ?>`

这是我到目前为止,我应该使用post而不是get?

1 个答案:

答案 0 :(得分:0)

您实际设置了查询但未执行该查询。 添加以下

$db->query();

之后

$db->setQuery($query);