【问题标题】:datatables search not work when field is out of table in database当字段不在数据库中的表中时,数据表搜索不起作用
【发布时间】:2018-10-21 07:32:01
【问题描述】:

我使用具有默认设置和服务器处理的简单数据表。
我的服务器端代码是这样的:

$table = 'lead';
$primaryKey = 'id';
$colnowid = 2;
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case object
// parameter names

include_once( 'jdf.php' );
include_once( 'config.php' );

$columns = array(

array(
    'db' => 'id',
    'dt' => 'id',
    'formatter' => function ( $d, $row ) {
        if(1 == 1 ){
           return  '<a href="lead-add.php?id='.$d.'">ویرایش</a> ';
        }
    }
),
array(
    'db' => 'type',
    'dt' => 'type',
    'formatter' => function ( $d, $row ) {
        global $colnowid;
        return '<a href="lead-view.php?id='.$colnowid.'">'.$d.'</a>';
    }
),
array(
    'db' => 'cat',
    'dt' => 'cat',
    'formatter' => function ( $d, $row ) {
        return $d;
    }
),
array(
    'db' => 'contact_id',
    'dt' => 'contact_id',
    'formatter' => function ( $d, $row ) {
        if ( !isset( $db ) ) {
            $db = db();
        }
        if($d != '') {
            $c = qselect("select name from contact where id = $d limit 1",$db);

            return $c['name'];
        } else { 
            return '';
        }
    }
),
// SQL server connection information
$sql_details = array(
    'user' => $dbuser,
    'pass' => $dbpass,
    'db' => $dbname,
    'host' => 'localhost'
);

require( 'ssp.class.php' );
$db = db();
echo json_encode( SSP::simple( $_POST, $sql_details, $table, $primaryKey, $columns ) );die;

一切正常。
我对类型、猫和其他人的搜索工作正常,
但它不搜索联系人姓名,因为我是从另一个表中获取的。
那么,知道如何实现这一点吗?

【问题讨论】:

  • 联系人的“格式化程序”中有错字:}$return $c['name']; 之前太多了
  • @Jeff 是的,对不起,但我在这里编辑的代码是正确的,所以你可以很容易地看到它并且犯了错误..无论如何你知道我的答案吗?
  • 从这里找到了我的答案。希望它可以帮助其他人how add join to your datatables

标签: php datatable datatables datatables-1.10


【解决方案1】:

How to join two tables with ssp.class.php
从这里找到我的答案
它在服务器端脚本中添加连接和位置,以便您可以连接表以进行搜索

【讨论】:

    猜你喜欢
    • 2014-05-25
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    相关资源
    最近更新 更多