Iceman512 Posted August 9, 2007 Share Posted August 9, 2007 Hi everyone, Could someone please shed some light on the correct use of brackets { and } in a MySQL query. For example, I understand that the following query is not entirely correct: <?php $sql = "SELECT id, title, date, description, publish FROM $dbtable WHERE title LIKE '$search%' || body LIKE '$search%' && publish='yes' ORDER by id DESC LIMIT '$offset', '$limit'"; ?> Rather, the following should be used but is this actually correct?: <?php $sql = "SELECT id, title, date, description, publish FROM $dbtable WHERE title LIKE '{$search}%' || body LIKE '{$search}%' && publish='yes' ORDER by id DESC LIMIT '{$offset}', '{$limit}'"; ?> I have looked this up on the net, but there seem to be many conflicting opinions. Thanks to anyone who can shed some light. Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/64047-correct-use-of-brackets/ Share on other sites More sharing options...
MadTechie Posted August 9, 2007 Share Posted August 9, 2007 personally i only use{} when i include an array ie $sql = "SELECT id, title, date, description, publish FROM $dbtable WHERE title LIKE '$search%' || body LIKE '$search%' && publish='{DATA['publish']}' ORDER by id DESC LIMIT '$offset', '$limit'"; note the publish='{DATA['publish']}' Quote Link to comment https://forums.phpfreaks.com/topic/64047-correct-use-of-brackets/#findComment-319236 Share on other sites More sharing options...
HuggieBear Posted August 9, 2007 Share Posted August 9, 2007 Check out the Variable Parsing in the PHP manual for a better understanding. It covers both simple and complex (curly) syntax. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/64047-correct-use-of-brackets/#findComment-319242 Share on other sites More sharing options...
Iceman512 Posted August 9, 2007 Author Share Posted August 9, 2007 Ok, I see. Thanks for the replies. I'll take a look. Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/64047-correct-use-of-brackets/#findComment-319245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.