【问题标题】:Delete row from database in administrator在管理员中从数据库中删除行
【发布时间】:2014-03-18 08:13:15
【问题描述】:

我有一个组件,我想在管理员中添加一个删除按钮,但我无法让它工作。这是我的代码(所有注释的行,我都试过了):

`<?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 吗?

【问题讨论】:

  • exact 错误是什么? stackoverflow.com/help/mcve
  • 我没有任何错误,只是没有删除我的行。
  • 嗨,好的,首先,删除所有你不使用的代码,这样会更容易阅读。其次,不要使用$_GET,请阅读this。您已经注释掉了 delete 执行的两种数据库查询方法,您使用的是哪一种?
  • 好的,我会阅读该页面。谢谢。
  • @RMissy - 请使用您正在使用的代码编辑您的问题,并删除您使用的任何代码

标签: database joomla delete-row corresponding-records


【解决方案1】:

您实际上设置了查询但没有执行它。 添加以下内容

$db-&gt;query();

之后

$db->setQuery($query);

【讨论】:

  • 谢谢,但还是一样。
  • $db->setQuery() 和 $db->query() 是不同的,无论如何要告诉将执行什么查询 echo $query->dump();然后我们可以看看查询是否设置好了
  • 对不起,我的意思是我也使用了你的想法,它是一样的。它不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-13
  • 1970-01-01
  • 2012-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多