Jump to content

Correct use of brackets


Iceman512

Recommended Posts

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

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']}'

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.