Re: Quotes vs. Single Quote

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Aug 5, 2010, at 10:10 PM, Rick Dwyer wrote:

> Hi List.
> I've mentioned before that I am both just beginning to learn PHP AND I have inherited a number of pages that I'm trying to clean up the w3c validation on.
> 
> Something that confuses me is how the code on the page is written where in one instance, it follows this:
> 
> echo "<table border='1'><tr>....
> 
> And elsewhere on the page it follows:
> 
> echo '<table border="1"><tr>....
> 
> In what I've read and from many of the suggestions from this board, the latter seems to be the better way to code, generally speaking.
> 
> So given that the page has javascript in it, perhaps the reason for the previous developer switching between the two was for ease of incorporating JS?.... Don't really know... but what I would like to know is it considered poor coding switch between the two on a single page or is it perfectly acceptable?
> 
> 2nd question, in the 3 lines below:
> 
> $_SESSION['newpage'] = $newpage;
> $checkstat = "select field from table where fieldid = $field_id";
> $result1 = @mysql_query($checkstat,$connection) or die("Couldn't execute query");
> 
> 
> If I were to recode in the latter style, should they not look like this:
> 
> $_SESSION['newpage'] = $newpage;
> $checkstat = 'select field from table where fieldid = "'.$field_id.'"';
> $result1 = @mysql_query($checkstat,$connection) or die('Couldn\'t execute query');
> 
> 
> The focus being here:
> 
> "'.$field_id.'"';
> ('Couldn\'t execute query')
> 
> Is this correct?
> 
> Thanks for the help.
> 
> --Rick
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
Rick-

It is generally accepted that you should use single quotes whenever possible. I only use double quotes when writing SQL queries (so I don't have to continually escape them for the single quotes) and when I need to output control characters like "\r" or "\n". 

It would be considered "best practice" to make consistent use of them, but it wouldn't be something I would loose sleep over.

Regards,

-Josh
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux