Jump to content

Using quotes


eleven0

Recommended Posts

$query = "SELECT * FROM ***** WHERE ID_BOARD='16' ORDER BY posterTime DESC";

$result = mysql_query($query) or die(mysql_error());


// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<div class='tborder45'><div class='tborder22'>{$row['subject']}</div>";
echo "<font face='Trebuchet ms' size='2'>{$row['body']} </face>";
echo "<br />";
}
include 'closedb.php';
}

 

This is just asking.

Just want to make sure something. code above gets data from my database. I'm having some other problem and I asked a person about it. He asked me why i was using double quotes for echoing. He said I should be using single quotes for echos and double for tables and such. Just to make clear, this code works it gets the data without any problem.

 

I use double quotes because when i'm echoing a text that has a single quote, it works.

 

So Am i using them right?

Link to comment
Share on other sites

There is a small amount of overhead added by PHP in using double quotes.  The reason for this is because you can embed PHP variables in double quotes, like you've done here:

echo "<div class='tborder45'><div class='tborder22'>{$row['subject']}</div>";

 

I also tend to use double quotes for MySQL queries because most queries will contain single quotes somewhere in them.

 

IMO, unless your site is huge in popularity and you can pinpoint major sight slowdown to the extra overhead incurred by using double quotes, then it doesn't really matter.  But if your site is so popular that single quotes vs. double quotes is an issue, then you can probably afford a second dedicated server so that Apache can run on one and MySQL can run on the other.

 

Likewise, I've heard about programmers that spent hours modifying code to remove all the double quotes and then the script runs an average of .001ms faster.  Big deal.  Then you turn around and they're running a query on several hundred thousand rows without an index defined.

 

There are a lot of things you can worry about when optimizing your programs.  IMO, single quotes vs. double quotes should not be one of them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.