ryansuitposungkono / openjs-grid

Automatically exported from code.google.com/p/openjs-grid
0 stars 0 forks source link

Joining Tables not working #69

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
What I'm trying to do is join two tables, but its picking my original table 
instead of adding the 2nd one. 

// require our class
    require_once("grid.php");
    // load our grid with a table
    $grid = new Grid("drivers");    
    $grid->joins = array(
        "LEFT JOIN points ON (points.DriverID = drivers.DriverID)"
    );
    // for editing check for the save flag and call save
    if(isset($_POST['save'])) {
        //$grid->security = array("n_items");
        echo $grid->save();
    } else if(isset($_POST['add'])) {
        $grid->add();
    } else if(isset($_POST['delete'])) {
        $grid->delete();    
    } else {
        $grid->load();
        echo json_encode($grid->data);
    }   

is my current ajax.php file, minus the database connection settings.

What is the expected output? What do you see instead?
The expect output is to have a grid where I can choose from both tables. What 
happens is all the col's are being headed with my drivers."col" table in the 
SELECT Statement. 

SELECT 
`drivers`.`FirstName`,`drivers`.`LastName`,`drivers`.`Make`,`drivers`.`Event1`,`
drivers`.`Event2`,`drivers`.`Event3`,`drivers`.`Event4`,`drivers`.`Event5`,drive
rs.DriverID
            FROM `drivers`
            LEFT JOIN points ON (points.DriverID = drivers.DriverID)

What version of the product are you using? On what operating system?
1.8, on linux Apache version 2.2.21 PHP version 5.2.17 MySQL version    5.1.52-cll

Please provide any additional information below.

I just can't figure out where to set it to choose the right table from the 
joined ones. Using what was listed on the documentation to do the join. 

Original issue reported on code.google.com by jet.bec...@gmail.com on 13 Mar 2012 at 9:25

GoogleCodeExporter commented 9 years ago
after $grid->joins
you should have list of fields to display from join table, i.e.:
$grid->fields = array(
            "points"=>"points.ID",
            "Date"=>"points.Date",
            "Expires"=>"points.Expires"
        );

Original comment by ginger...@gmail.com on 14 Mar 2012 at 1:02

GoogleCodeExporter commented 9 years ago
Thanks so much, it works fantastically. I'm also trying to figure out how to be 
able to update/delete the columns in the points table, from the grid I just 
made above. Again the problem is that the UPDATE is only set to using the 
drivers table and not the points table. 

Original comment by jet.bec...@gmail.com on 14 Mar 2012 at 3:21

GoogleCodeExporter commented 9 years ago
i'm currently facing the same problem. at the moment i have two separate grids 
to manage each table, but this isn't perfect.
without some fundamental changes to this grid it doesn't seem to be possible..

in php grid object you should first be able to accept 2 (or more) tables, then 
submit retrieved data to js grid (this should be handled with minor 
adjustments), but still be able to identify which amendments relates to each 
table 

Original comment by ginger...@gmail.com on 14 Mar 2012 at 4:47