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 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']}' 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 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 Link to comment https://forums.phpfreaks.com/topic/64047-correct-use-of-brackets/#findComment-319245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.