0

私は prestashop のタブを作成しており、顧客と出身国を一覧表示しています。ここまでは問題ありませんが、クエリまたはテーブルを国別にフィルター処理したいので、次のようなものを追加したいと思います: WHERE iso_code = 'IT' これは私のコードです:

<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminCustomersCountries extends AdminTab
{
    public function __construct()
    {
        $this->table = 'customer';
        $this->className = 'Customer';
        $this->lang = false;
        $this->edit = false;
        $this->view = true;
        $this->delete = false;
        $this->deleted = false;
        $this->requiredDatabase = true;

        $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country) AS iso_code';
        $this->fieldsDisplay = array(
        'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
        'lastname' => array('title' => $this->l('Last Name'), 'width' => 80),
        'firstname' => array('title' => $this->l('First name'), 'width' => 60),
        'email' => array('title' => $this->l('E-mail address'), 'width' => 120, 'maxlength' => 19),
        'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
        'newsletter' => array('title' => $this->l('News.'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'callback' => 'printNewsIcon', 'orderby' => false),
        'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false));

        $this->optionTitle = "Prova";
        parent::__construct();
    }

    public function postProcess()
    {
        // This function is executed when the Submit button is clicked
        // Use it to store the value of text fields in the database

        parent::postProcess();
    }

    public function displayForm($token=NULL)
    {
        // This function can be used to create a form with text fields
    }
}

?>

ただし、ここで WHERE 句を追加しようとしましたが、結果はありません。

<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminCustomersCountries extends AdminTab
{
    public function __construct()
    {
        $this->table = 'customer';
        $this->className = 'Customer';
        $this->lang = false;
        $this->edit = false;
        $this->view = true;
        $this->delete = false;
        $this->deleted = false;
        $this->requiredDatabase = true;

        $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country AND cy.iso_code='IT') AS iso_code';
        $this->fieldsDisplay = array(
        'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
        'lastname' => array('title' => $this->l('Last Name'), 'width' => 80),
        'firstname' => array('title' => $this->l('First name'), 'width' => 60),
        'email' => array('title' => $this->l('E-mail address'), 'width' => 120, 'maxlength' => 19),
        'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
        'newsletter' => array('title' => $this->l('News.'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'callback' => 'printNewsIcon', 'orderby' => false),
        'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false));

        $this->optionTitle = "Prova";
        parent::__construct();
    }

    public function postProcess()
    {
        // This function is executed when the Submit button is clicked
        // Use it to store the value of text fields in the database

        parent::postProcess();
    }

    public function displayForm($token=NULL)
    {
        // This function can be used to create a form with text fields
    }
}

?>
4

2 に答える 2

0

この行$this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country AND cy.iso_code='IT') AS iso_code';は、 を使用して IT を検索し'IT'ます。

アポストロフィがエスケープされていないため、PHP は IT を読み取りません。を使用するとうまくいくと思いますAND cy.iso_code=\'IT\')

于 2013-06-01T13:39:23.410 に答える