سؤال

I am using the datatables server-side processing: http://datatables.net/release-datatables/examples/data_sources/server_side.html. But how can i get data from two tables?

هل كانت مفيدة؟

المحلول

      Here is the query which gets data from two tables in server side.php
      SELECT SQL_CALC_FOUND_ROWS u.user_id,u.user_name,u.user_image,u.email,p.id,
      p.image,p.description,p.comments,p.stock,p.timestamp,p.link,p.store,p.buy
      FROM users u
      INNER JOIN product p
      ON u.user_id=p.user_id
      $sWhere
      $sOrder
      $sLimit
      ";

نصائح أخرى

Do it in this part of the example code:

$sQuery = "
    SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $aColumns))."
    FROM   $sTable
            LEFT JOIN secondTable  ON secondTable.id = ".$table.".id
    $sWhere
    $sOrder
    $sLimit
    ";

Beware that the additional fields should have respective cells in your html and the proper names in your columndefs.

Take @Vegetas advice for real. This is very basic PHP and SQL Stuff.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top