从点击结果中删除记录

时间:2017-01-07 02:52:09

标签: php mysql arrays onclick display

我有一个问题,如果我说错了,但我无法找到它,我会想到之前肯定会被问过。这个问题需要一些单独的代码片段来解决。我有一个应用程序,我们用它来审查从某些表单提交给我们客户的潜在客户的有效性,以便进行计费。我想要的是,当用户按下“有效”或“无效”按钮时,它会为潜在客户指定正确状态并将其从当前显示的表中删除,这将是“需要审核”的引导。这些潜在客户的需求审核值为'null',这是默认值。按下按钮时,其他引线分配适当的值1或0.

一切正常,我唯一无法弄清楚的是如何不重定向用户重启点击搜索。我只是希望它从当前显示的内容中删除记录。这是一些代码,我将非常感谢任何帮助。同样,这一切都有效,只是不是最方便的方式,我不知道如何以更好的方式做到这一点,我只需要一个更有经验的人指出我正确的方向。

这是按钮代码:

          <td style="background:#fff;border:none;">
          <button  style="margin-bottom:2.5%;margin-top:2.5%;background:#2ECC71;border-radius:5px;width:175px;height:30px;border:3px solid #3FC380;color:#fff;font-weight:bold;" onclick="location='admin.php?action=validCustomer&amp;customersId=<?php echo $customers->id?>'">Valid</button>
      </td>
      <td style="background:#fff;border:none;">
            <button  style="margin-bottom:2.5%;margin-top:2.5%;background:#2ECC71;border-radius:5px;width:175px;height:30px;border:3px solid #3FC380;color:#fff;font-weight:bold;" onclick="location='admin.php?action=invalidCustomer&amp;customersId=<?php echo $customers->id?>'">Not Valid</button>
      </td>

以下是其他相关代码:

function searchIsValid() {
$results['formAction'] = "searchIsValid";
$results['pageTitle'] = "Search By Validation Status";
require (TEMPLATE_PATH . "/admin/searchIsValid.php" );
}
function validCustomer(){
if (!$customers = customers::getById( (int)$_GET['customersId'] ) ){
    echo "Error getting customer ID";
}
$results['formAction'] = "validCustomer";
$results['pageTitle'] = "Lead Validated";
$customers->validCustomer($_SESSION['username']);
header( "Location: admin.php?action=searchIsValid" );
}
function invalidCustomer(){
if (!$customers = customers::getById( (int)$_GET['customersId'] ) ){
    echo "Error getting customer ID";
}
$results['formAction'] = "invalidCustomer";
$results['pageTitle'] = "Lead Invalidated";
$customers->invalidCustomer($_SESSION['username']);
header( "Location: admin.php?action=searchIsValid" );
}

最后,最后一段相关代码,SQL部分:

public function update() {

// Does the customer object have an ID?
if ( is_null( $this->id ) ) trigger_error ( "customers::update(): Attempt to update a customer object that does not have its ID property set.", E_USER_ERROR      );

// Update the customer
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "UPDATE leads SET valid=:valid WHERE id = :id";
$st = $conn->prepare ( $sql );
$st->bindValue( ":id", $this->id, PDO::PARAM_INT );
$st->execute();
$conn = null;
}

public function validCustomer($username) {

// Does the customer object have an ID?
if ( is_null( $this->id ) ) trigger_error ( "customers::update(): Attempt to update a customer object that does not have its ID property set.", E_USER_ERROR );



 // Update the customer
    $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
    // if invalid
     $sql = "UPDATE leads SET valid=1, reviewedby='$username' WHERE id = :id";
        $st = $conn->prepare ( $sql );
        $st->bindValue( ":id", $this->id, PDO::PARAM_INT );
        $st->execute();
        $conn = null;
     }
     public function invalidCustomer($username) {

    // Does the customer object have an ID?
    if ( is_null( $this->id ) ) trigger_error ( "customers::update(): Attempt to update a customer object that does not have its ID property set.", E_USER_ERROR );

    // Update the customer
    $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
    // if invalid
     $sql = "UPDATE leads SET valid=0, reviewedby='$username' WHERE id = :id";
        $st = $conn->prepare ( $sql );
        $st->bindValue( ":id", $this->id, PDO::PARAM_INT );
        $st->execute();
        $conn = null;
    }

我认为这是所有相关的代码,但我可能已经忘了一些,所以请随时提醒我,并再次感谢您花时间阅读我的帖子并提供帮助!

0 个答案:

没有答案