Jump to content

[SOLVED] Query using multiple tables?


AbydosGater

Recommended Posts

Hi, Im having some trouble using table joins to pull plugin data and block data for my site all at once in one query.

Im using the following query:

		   SELECT
                                  `sb_blocks`.`bID`,
                                  `sb_blocks`.`title`,
                                  `sb_blocks`.`bFile`,
                                  `sb_plugins`.`pDir`,
                                  `sb_plugins`.`pFile`
                            FROM
                                  `sb_blocks`,
                                  `sb_plugins`,
                            WHERE
                                  `sb_blocks`.`pluginID` = `sb_plugins`.`pID` AND
                                  `sb_plugins`.`status` = 'init'
                            ORDER BY
                                  `sb_blocks`.`priority`

Its not getting any results. The data is there. But when i run it via PhpMyAdmin i get the following error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE  `sb_blocks` . `pluginID` = `sb_plugins` . `pID` AND  `sb_plugins` . `stat' at line 1

 

But i dont know. I cant see where im going wrong.

Im sorry if its simple its the first time i have normalised my data this much and used multiple tables in one statment. 3:30 AM now but im trying to get this finished before tomorrow. Can anyone spot the error?

 

Thanks Andy

Link to comment
https://forums.phpfreaks.com/topic/60145-solved-query-using-multiple-tables/
Share on other sites

You have a comma in there that shouldn't be.

 

Try this:

<?php
		   SELECT
                                  `sb_blocks`.`bID`,
                                  `sb_blocks`.`title`,
                                  `sb_blocks`.`bFile`,
                                  `sb_plugins`.`pDir`,
                                  `sb_plugins`.`pFile`
                            FROM
                                  `sb_blocks`,
                                  `sb_plugins` //<---comma was here
                            WHERE
                                  `sb_blocks`.`pluginID` = `sb_plugins`.`pID` AND
                                  `sb_plugins`.`status` = 'init'
                            ORDER BY
                                  `sb_blocks`.`priority`
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.