Use datatables with queries

Use datatables with queries

PriximmoPriximmo Posts: 1Questions: 0Answers: 0
edited March 2012 in General
Hello,

I'm sorry but I use so simply datables but now I want to use this with a queries.

My queries is :

SELECT s_a_application.S_A_ID_APPLICATION, S_A_NOM, S_A_DESC_SUCCINCT, S_M_NOM FROM s_a_application LEFT JOIN s_m_theme ON s_m_theme.S_A_ID_APPLICATION = s_a_application.S_A_ID_APPLICATION

Can you help me ?

Thx

Replies

  • PeteBPeteB Posts: 38Questions: 0Answers: 0
    Some searches for PHP and MySQL in the forum will lead you to the server-side script example.

    This is how I amended mine:
    [code]
    <?php

    /*
    * Script: DataTables server-side script for PHP and MySQL
    * Copyright: 2010 - Allan Jardine
    * License: GPL v2 or BSD (3-point)
    */

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Easy set variables
    */

    /* Array of database columns which should be read and sent back to DataTables. Use a space where
    * you want to insert a non-database field (for example a counter or static image)
    */
    $aColumns = array( 'hpID', 'honname', 'seasonID', 'lastnme', 'firstnme' );


    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "hpID";

    /* DB table to use */
    $sTable1 = "honourplayers";
    $sTable2 = "honours";
    $sTable3 = "players";

    $sTable = $sTable1 . ' LEFT JOIN ' . $sTable2 . ' ON (' . $sTable2 . '.honourID = ' . $sTable1 . '.honourID)';
    $sTable = $sTable . ' LEFT JOIN ' . $sTable3 . ' ON (' . $sTable3 . '.playerID = ' . $sTable1 . '.playerID)';


    /* Database connection information */
    $gaSql['user'] = "xxxx";
    $gaSql['password'] = "xxxx";
    $gaSql['db'] = "xxxx";
    $gaSql['server'] = "xxxx";



    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * If you just want to use the basic configuration for DataTables with PHP server-side, there is
    * no need to edit below this line
    */

    /*
    * MySQL connection
    */
    $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
    die( 'Could not open connection to server' );

    mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
    die( 'Could not select database '. $gaSql['db'] );


    /*
    * Paging
    */
    $sLimit = "";
    if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
    {
    $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
    mysql_real_escape_string( $_GET['iDisplayLength'] );
    }


    /*
    * Ordering
    */
    $sOrder = "";
    if ( isset( $_GET['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i $iFilteredTotal,
    "aaData" => array()
    );

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
    $row = array();
    for ( $i=0 ; $i
    [/code]

    There may be a more efficient way of doing it, but it works for me ;)

    Pete.
This discussion has been closed.