Jquery Datatables服务器端处理内部联接或多个表

Jquery Datatables服务器端处理内部联接或多个表,jquery,jquery-plugins,datatables,Jquery,Jquery Plugins,Datatables,下面是我的代码,没有服务器端处理,但由于它会产生许多行,并且会显著增长,因此我需要使用服务器端处理 DB表(不包括所有字段,但这些是我想要的字段和要内部连接的字段): 我希望能够将UNIXTIMESTAMP显示为日期(“d/m/Y”) 这对内部连接有效吗 $sQuery = " SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))." FROM $sTable

下面是我的代码,没有服务器端处理,但由于它会产生许多行,并且会显著增长,因此我需要使用服务器端处理


DB表(不包括所有字段,但这些是我想要的字段和要内部连接的字段):

我希望能够将UNIXTIMESTAMP显示为日期(“d/m/Y”)


这对内部连接有效吗

$sQuery = "
    SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
    FROM   $sTable 
    INNER JOIN modules ON $sTable.module = modules.id 
    INNER JOIN course ON $sTable.course = course.id 
    INNER JOIN course_categories ON course.category = course_categories.id
    $sWhere
    $sOrder
    $sLimit
";

未经服务器端处理的原始php版本:

$mods = get_records_sql("SELECT * FROM {$CFG->prefix}course_modules");

foreach ($mods as $mod)
    {

    $thecourse = get_record('course','id',$mod->course); 
    $themodule = get_record('modules','id',$mod->module); 
    $thecat = get_record('course_categories','id',$thecourse->category); 


    echo '<tr>'; 
    echo '<td>'.$thecat->name.'</td>'; 
    echo '<td>'.$thecourse->fullname.'</td>'; 
    echo '<td>'.$themodule->name.'</td>'; 
    echo '<td>';
    echo date('d/m/Y', $mod->added);
    echo'</td>'; 
    echo '</tr>'; 
    } 
$mods=get_records_sql(“从{$CFG->prefix}课程模块中选择*);
foreach($mods作为$mod)
{
$thecourse=get_记录('course','id',$mod->course);
$themodule=get_记录('modules','id',$mod->module);
$thecat=get_记录('course_categories','id',$thecourse->categority);
回声';
回显“.$thecat->name.”;
回显“.$thecourse->fullname.”;
回显“.$themodule->name.”;
回声';
回显日期('d/m/Y',$mod->added);
回声';
回声';
} 
我的数据表的服务器端处理工作正常,但没有链接到其他表。此表仅返回ID,我希望能够从另一个表中获取值,如上所示

我需要使用Inner连接吗?如果是,我如何与server_processing.php脚本合并: 我用了这个:

或者我可以将上述方法合并到server_processing.php中

任何指导都将不胜感激。
提前感谢。

是的,我认为您应该使用内部联接(但我需要更多关于表的详细信息来编写精确的查询),然后您必须在此处修改sql

  $sQuery = "
    SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
    FROM   $sTable
    $sWhere
    $sOrder
    $sLimit
";
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
编辑-要记录查询,请执行以下操作:

$filename = __DIR__.DIRECTORY_SEPARATOR."logging.txt";

file_put_contents($filename, $sQuery, FILE_APPEND);
您应该在脚本的同一目录中有一个logging.txt文件。请回答以下问题: 问题是有两个列名相同,所以我在SQL查询中使用了alises。 也没有使用内部连接

使用别名和列名的列数组:

$aColumns = array( 'catname', 'fullname', 'modulename', 'added');
4个表的SQL查询:

$sQuery = "
    SELECT mdl_course.fullname, mdl_modules.name AS modulename, mdl_course_categories.name AS catname, mdl_course_modules.added
    FROM  mdl_course_modules, mdl_modules, mdl_course, mdl_course_categories
    WHERE mdl_course_modules.module = mdl_modules.id AND mdl_course_modules.course = mdl_course.id AND mdl_course.category = mdl_course_categories.id
    $sOrder
    $sLimit
";
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());

@:Nicola Peluchetti:我用DB结构修改了这个问题。谢谢@:Nicola Peluchetti:my Internal JOIN更新,这看起来对吗?@Codded是的,它应该可以工作,但在任何情况下,您都应该记录查询(可以使用FireHP)并在mysql中验证它是否正确@:Nicola Peluchetti:im getting-DataTables警告:无法解析来自服务器的JSON数据。这是由JSON格式错误引起的。这是正确的吗$aColumns=数组('course.fullname','modules.name','course\u categories.name','course\u modules.added')@Codded是的,这可能是原因,但可能只是PHP出错(可能查询无效)并输出通知,因此无法解析json
$sQuery = "
    SELECT mdl_course.fullname, mdl_modules.name AS modulename, mdl_course_categories.name AS catname, mdl_course_modules.added
    FROM  mdl_course_modules, mdl_modules, mdl_course, mdl_course_categories
    WHERE mdl_course_modules.module = mdl_modules.id AND mdl_course_modules.course = mdl_course.id AND mdl_course.category = mdl_course_categories.id
    $sOrder
    $sLimit
";
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());