a few syntax questions.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wizbang
Forum Newbie
Posts: 1
Joined: Thu Apr 28, 2005 8:55 pm

a few syntax questions.

Post by wizbang »

Hi,
I can't seem to find a reference to this and I'd like to understand what it means
it's part of a MySQL query written in php that I found on a post.
(i am new to php)

Code: Select all

$sql = "
    SELECT  *
    FROM    `name_of_table`
    WHERE   ".$query."
;"

$res = mysql_query($sql);
What do the periods mean?
Why are they necessary?

Periods don't seem to be needed all the time because i have used
something similar to:
$num = result_of_some_function();
echo "there are $num results";
which embedded the result of the function in the output.

Additionally, in my research so far from the mysql manual on the SELECT statement it indicates nothing about using `s.
i am curious about the following statement

Code: Select all

FROM `name_of_table`
what is the difference between FROM name_of_table and FROM `name_of_table`?

(using the `s) I have written queries with and without. (that's a little troubling if that syntax IS reqired)
Is it necessary is what I am asking.
Thanks for the input.
many regards,
wiz
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

In PHP periods/dots are concatenation symbol. Similar to + in JavaScript As far as I know the backticks are optional SQL Syntax
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I almost always use concatenation since syntax highlighting makes it much clearer where the variables are in a string and you don't need to escape double-quotes in html tags. However, linefeeds \n or tabs \t must be double-quoted.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

I almost always use concatenation since syntax highlighting makes it much clearer where the variables are in a string
not if you use vim (or something similar). :P
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

as for the field names, the "`" are required for field names that might have operators in them:

ex:

FN: the-store would have to have the "`" in them otherwise it will think your subtracting something:

Code: Select all

update myTable set `the-store` = 'bob' where id=54
with that you might actually even be able to have spaces in field names...although I've never tried and prolly never will....
Post Reply