Jump to content

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`
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.