Server Side processing

Server Side processing

staticstatestaticstate Posts: 8Questions: 3Answers: 0

Hello, if i have a table with lets say a colum that has a data "2" but "2" is a reference on another table like if 2 is Name.
How can i make it display the name an not the number 2..

Table 1 (this is how it displays it)

| Id | name | last_name | area |
| 1 | 23 | 53 | 51 |

table 2

| Id | name_id | name |
| 1 | 23 |Steve |

table 3

| Id | name_id | last_name |
| 1 | 53 | Butabi |

table 4

| Id | area_id | name |
| 1 | 51 |Home |

table 5 ( this is how i want it to be shown)

| Id | name | last_name | area |
| 1 | Steve | Butabi |Home|

thanks...

Answers

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39

    Sounds like you want to do this?

    SELECT
        table1.id,
        table2.name,
        table3.last_name,
        table4.name as 'area'
    FROM
        table1
    LEFT JOIN
        table2
    ON
        table1.name = table2.name_id
    LEFT JOIN
        table3
    ON
        table1.last_name = table3.name_id
    LEFT JOIN
        table4
    ON
        table1.area = table5.area_id
    
  • staticstatestaticstate Posts: 8Questions: 3Answers: 0

    hello, Igni yes i would like to do something like that but on server side processing.
    what changes would i have to make on the file server_processing.php?

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39

    Your columns array in server_processing.php should look like this:

    $columns = array(
        array( 'db' => 'id',        'dt' => 0 ),
        array( 'db' => 'name',      'dt' => 1 ),
        array( 'db' => 'last_name', 'dt' => 2 ),
        array( 'db' => 'area',      'dt' => 3 )
    );
    

    Then in ssp.class.php you can add this inside the simple function, before $data is set.

    $subquery = "
    SELECT
        table1.id,
        table2.name,
        table3.last_name,
        table4.name as 'area'
    FROM
        table1
    LEFT JOIN
        table2
    ON
        table1.name = table2.name_id
    LEFT JOIN
        table3
    ON
        table1.last_name = table3.name_id
    LEFT JOIN
        table4
    ON
        table1.area = table5.area_id";
    

    Then in that same function where $data is set to the SQL query, change FROM '$table' to FROM ($subquery) with no tilde or quotes.

  • staticstatestaticstate Posts: 8Questions: 3Answers: 0
    edited March 2015

    thnx Igni for the constant help you have given.. im still kinda confuse... so ill put exactly my tables and columns of my query and thanx again for the help.

    this is what i see when i render the table

    <table>
    <tr>  
    <th>[call_id]</th> 
    <th>[call_name]</th> 
    <th>[date.............]</th> 
    <th>[call_details]</th> 
    <th>[call_staff]</th> 
    <th>[call_user]</th> 
    </tr>
    <tr> 
    <td>[1]</td>
    <td>[23]</td>
    <td>[1422889860]</td>
    <td>[Lorem Ipsu]</td>
    <td>[5]</td>
    <td>[7]</td>
    </tr>
     </table>
    

    call_name makes reference to table site_clientes

    <table>
    <tr>  
    <th>[call_id]</th> 
    <th>[call_cliente]</th> 
    
    </tr>
    <tr> 
    <td>[23]</td>
    <td>[Name]</td>
    
    </tr>
     </table>
    

    date (actually i dont know how to transform to normal date

    call_details (is ok)

    call_staff and call user makes reference to table site_users

    <table>
    <tr>  
    <th>[user_id]</th> 
    <th>[user_name]</th> 
    
    </tr>
    <tr> 
    <td>[5]</td>
    <td>[Name5]</td></tr><tr>  
    <td>[7]</td>
    <td>[Name7]</td>
    
    </tr>
     </table>
    

    this is what should be the result

    <table>
    <tr>  
    <th>[call_id]</th> 
    <th>[call_name]</th> 
    <th>[date.............]</th> 
    <th>[call_details]</th> 
    <th>[call_staff]</th> 
    <th>[call_user]</th> 
    </tr>
    <tr> 
    <td>[1]</td>
    <td>[Name]</td>
    <td>[2015-03-05 / 9:49 am ]</td>
    <td>[Lorem Ipsu]</td>
    <td>[Name5]</td>
    <td>[Name6]</td>
    </tr>
     </table>
    

    thanx again
    btw i dont have ssp.class.php it makes everything on the server_processing.php file

This discussion has been closed.