PHP Classes

SQL Joins

Recommend this page to a friend!

      DrasticTools  >  All threads  >  SQL Joins  >  (Un) Subscribe thread alerts  
Subject:SQL Joins
Summary:Is it possible?
Messages:5
Author:DMM
Date:2009-01-08 12:57:43
Update:2009-04-09 09:42:16
 

  1. SQL Joins   Reply   Report abuse  
Picture of DMM DMM - 2009-01-08 12:57:43
I have two tables that I'd like to join for a dataset of selected columns. I'm doing the following in a test script:

<?php
define("PATHDRASTICTOOLS", "");
include(PATHDRASTICTOOLS."Examplemysqlconfig2.php");
include(PATHDRASTICTOOLS."drasticSrcMySQL.class.php");
class mysrc extends drasticsrcmysql {
protected function select(){
$res = mysql_query("SELECT a.ID, a.Title, b.MPAARating FROM $this->table1 b INNER JOIN $this->table2 a" . $this->orderbystr, $this->conn) or die(mysql_error());
return ($res);
}
}
$options = array (
"add_allowed" => false,
"delete_allowed" => false,
"editablecols" => array ()
);
$src = new drasticSrcMySQL($server, $user, $pw, $db, $table, $options);
$src->select();
?>

The "Examplemysqlconfig2.php" file looks like:
<?php
$server="localhost";
$user="dump_nc_ui_149";
$pw="********";
$db="dump_nc_ui_149";
$table="movies";
$table1="alternate_movie_titles";
$table2="movies";

$GApiKey="<put here your Google Maps API Key>";
?>

When the script is executed, the server returns the following message:

Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in /home/dump/webapps/flickpocket/drasticSrcMySQL.class.php on line 68
Could not find primary or unique key

The table definitions in the database are:

CREATE TABLE `alternate_movie_titles` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`MovieID` int(10) unsigned NOT NULL,
`Title` varchar(200) NOT NULL,
PRIMARY KEY (`ID`),
KEY `IDX_MovieID` (`MovieID`),
KEY `IDX_Title` (`Title`)
) ENGINE=MyISAM AUTO_INCREMENT=1175 DEFAULT CHARSET=utf8;

and...

CREATE TABLE `movies` (
`ID` int(10) unsigned NOT NULL,
`Title` varchar(200) NOT NULL,
`MPAARating` varchar(45) NOT NULL,
`ReleaseDate` datetime NOT NULL,
PRIMARY KEY (`ID`),
KEY `IDX_Title` (`Title`),
KEY `IDX_MPAARating` (`MPAARating`),
KEY `IDX_ReleaseDate` (`ReleaseDate`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Is it possible to do table joins with the DrasticTools grid component?

Thanks in advance for any information -

dmm

  2. Re: SQL Joins   Reply   Report abuse  
Picture of dd dd - 2009-01-12 21:15:55 - In reply to message 1 from DMM
Hi DMM,

I see no reason why drasticgrid could not work on a joined table, as long as you use the grid in a readonly way. But I must say I didn't test it out either, so I am not completely sure.

good luck,
dd

  3. Re: SQL Joins   Reply   Report abuse  
Picture of ali ahmed ali ahmed - 2009-03-31 15:34:50 - In reply to message 1 from DMM
plz if any1 has a work around to this problem plz post a solution...!!!

  4. Re: SQL Joins   Reply   Report abuse  
Picture of dd dd - 2009-03-31 19:38:10 - In reply to message 3 from ali ahmed
Hi,

Well, since we get this question a lot, we will seriously think how to support drasticgrid for two (joined) tables.
At least in readonly mode.

We will think it over for the coming release.

regards,

DrasticData

  5. Re: SQL Joins   Reply   Report abuse  
Picture of dd dd - 2009-04-09 09:42:16 - In reply to message 4 from dd
The support for table joins was not that easy as we thought it would in the first place. Today we released a new version of DrasticTools with a new version of Drasticgrid that has basic support for joined tables.
You can see an example of it on our website www.drasticdata.nl
The ExampleGrid10 combines two tables, joined on id's, into one grid.

regards,

DrasticData