简体   繁体   English

将数据表转换为cakephp连接表

[英]datatable into cakephp join tables

I have problem with datatables and script from http://datatables.net/development/server-side/php_cake to cakephp. 我对从http://datatables.net/development/server-side/php_cake到cakephp的数据表和脚本有问题。 I using it many time but no I have to use join and server response me 我已经使用了很多次,但是我不必使用加入和服务器响应

MySQL Error: 1052. MySQL错误:1052。

Problem is in this line : 问题在这一行:

$sTable = "`clients` AS c JOIN users AS u ON (c.user_id = u.id)";

When I print my all query and paste it in phpmyadmin everything is OK, but cake get error. 当我打印所有查询并将其粘贴到phpmyadmin中时,一切正常,但蛋糕得到了错误。

My generated SELECT : 我生成的SELECT:

SELECT SQL_CALC_FOUND_ROWS c.id, c.name, c.nip, c.adress, c.tel, c.tel2, c.email, c.created, c.id FROM clients c join users u ON(c.user_id = u.id) 选择SQL_CALC_FOUND_ROWS c.id,c.name,c.nip,c.adress,c.tel,c.tel2,c.email,c.created,c.id FROM客户端c加入用户u ON(c.user_id = u 。ID)

  ORDER BY c.id asc LIMIT 0, 10 

@edit @编辑

I modificated my script and now it generate something like this: 我修改了脚本,现在它生成如下内容:

SELECT SQL_CALC_FOUND_ROWS c . 选择SQL_CALC_FOUND_ROWS c id , c . idc name , c . name c nip , c . nipc adress , c . adress c tel , c . telc tel2 , c . tel2c email , c . emailc created , c . createdc id FROM clients AS c join users AS u ON c . 来自clients AS c id加入users AS u ON c user_id = u . user_id = u id

  ORDER BY `c`.`name` asc LIMIT 0, 10 

But it's still not work. 但这仍然行不通。 (I used char '`' before prefix and after and col name. ) (我在前缀和之后以及col名称之前使用了char'`'。)

you need create a view with the relationship!! 您需要使用关系创建视图!!

  1. Create the VIEW in MySql: 在MySql中创建VIEW:

     CREATE VIEW 'the_view' AS SELECT a.id, a.num_factura_proveedor, b.nombre_comercial FROM compras a INNER JOIN terceros b ON a.tercero_id = b.id 
  2. on the server side script: 在服务器端脚本上:

     $sTable = "the_view"; //the columns of the view $aColumns = array('id' , 'num_factura_proveedor', 'nombre_comercial'); $sIndexColumn = "id"; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM