Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
Todd_Z
- Forum Regular
- Posts: 708
- Joined: Thu Nov 25, 2004 9:53 pm
- Location: U Michigan
Post
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
-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
by feyd »
backtick all your table references and field references...
-
Todd_Z
- Forum Regular
- Posts: 708
- Joined: Thu Nov 25, 2004 9:53 pm
- Location: U Michigan
Post
by Todd_Z »
<shudder> thanks feyd...
-
Jenk
- DevNet Master
- Posts: 3587
- Joined: Mon Sep 19, 2005 6:24 am
- Location: London
Post
by Jenk »
Inner/left/right/outer join?
-
AGISB
- Forum Contributor
- Posts: 422
- Joined: Fri Jul 09, 2004 1:23 am
Post
by AGISB »
If you got phpmyadmin just echo out the statements and see what error in the syntax there is