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!
Use single quotes instead of double quotes and PHP will be slightly faster. This is because stuff within single quotes doesn't get parsed by the PHP engine whereas stuff in double quotes does. The other benefit of using single quotes is that you don't have to escape the double quotes around attributes in HTML. Do use double quotes around SQL statements though because you'll need to use single quotes within them.
$variable1 = 'SOMETHING SOMETHING '.$variable2.' SOMETHING '.function().' SOMETHING';
function1 ('SOMETHING SOMETHING SOMETHING '.$variable.' SOMETHING'.function2());
echo '<img src="thispic.jpg" alt="This pic" />';
$sql = "SELECT id, info FROM table WHERE something LIKE '".$something."' ORDER BY id";
Mac
*** edit (clarification) ***
You won't get a massive speed increase if you use single quotes instead of double quotes. You most likely will only notice a subtle/smallish difference (if you time these things of course ) if you have code that is called a lot or a loop with lots of iterations. The major benefit to using single quotes is being able to cut and paste HTML code into your PHP scripts and not having to go around escaping all the double quotes.
Last edited by twigletmac on Thu May 02, 2002 8:31 am, edited 2 times in total.
Actually, use single quotes so you don't have to escape the double quotes in your HTML. If your really looking for a speed increase, looking into the Zend Cache, faster hardware, or using C.
When I try to execute your query without first setting $pre_members to anything I got the same error message as you, but with this added to the beginning:
Warning: Undefined variable: pre_members in D:webdevsamscripts est.php on line 4
You have an error in your SQL syntax near '(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20), pass VARCHAR(20),' at line 1
Do you have warnings for uninitialised variables turned on?
As with cookies you need to make sure that no output has been sent before this or you'll get an error, and you need to terminate the script with exit after.