Page 1 of 1

Joins doing crazy things.

Posted: Sat Oct 29, 2005 12:00 pm
by Todd_Z

Code: Select all

$sql = "SELECT * FROM `Reviews` WHERE `For` = '{$_GET['q']}'";
	$mySQL->execSQL( $sql );
	while ( $rev = $mySQL->nextObject() ) {
		$sql = "SELECT `Title` FROM `Posts` WHERE `ID` = '{$rev->Project}'";
		$project = $mySQL->getField( $sql, "Title" );
		$sql = "SELECT `Name` FROM `Users` WHERE `ID` = '{$rev->By}'";
		$name = $mySQL->getField( $sql, "Name" );
		// print_r( $rev ); echo $project; echo $name;
	}
This should be able to be done using one sql - Something along the lines of

Code: Select all

$sql = "SELECT *, Users.Name, Posts.Title FROM `Reviews` JOIN `Users` ON ( Users.ID = Reviews.By ) JOIN `Posts` ON ( Posts.ID = Reviews.Project ) WHERE Reviews.For = 'X'";
Unfortunately, I get one of those "check the syntax around blahblah" errors.

MySQL ver 4.1.14

Posted: Sat Oct 29, 2005 12:31 pm
by feyd
backtick all your table references and field references...

Posted: Sat Oct 29, 2005 12:33 pm
by Todd_Z
<shudder> thanks feyd...

Posted: Sat Oct 29, 2005 1:16 pm
by Jenk
Inner/left/right/outer join?

Posted: Sun Oct 30, 2005 6:29 am
by AGISB
If you got phpmyadmin just echo out the statements and see what error in the syntax there is