Jump to content

[SOLVED] Whats wrong with this? (php mysql syntax)


monkeytooth

Recommended Posts

$query = " SELECT * FROM memb_pers " .
         " LIMIT $offset, $rowsPerPage " .
	 " WHERE c0unty = '$clocd' ";

 

the error is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE c0unty = 'Litchfield'' at line 1

 

 

I have no idea where I went wrong with this, it works without the WHERE clause, but then I added the WHERE and I think I did it right.. but im wrong so help?

no need for braces when using double quotes unless you're using arrays:

 

$name = 'Bob';
$names = array('first' => 'Bob');

echo "Hello, my name is $name<br />";
echo "Hello, my name is {$names['first']}<br />";

echo 'Hello, my name is '.$name;

 

for the record, you should always be using single quotes for strings that contain no variables - that way PHP doesn't have to waste resources scouring the string for variable references before echoing it.  read up on variable interpolation for more info.

Regarding the single/double quote thing. http://phpbench.com indicates that there is no difference.

 

i stand corrected!  thanks Daniel, always good to know something new.  i read an article quite some time ago which urged the use of single quotes for literals, i should have looked into it more.

your still talking minimal amounts and most of the time you are phrasing a string with variables (other wise php doesn't provide you a lot of usefulness) so I personally use double quotes and then ". to escape any variable.

<?php
$var = "yes";
echo "Do you like php?<br />".$var;
?>

 

If you use brackets or escape it php knows that variable name and won't waste a ton of resources trying to find a variable that doesn't exist thus it result in echoing it out or fatal error.

your still talking minimal amounts and most of the time you are phrasing a string with variables (other wise php doesn't provide you a lot of usefulness) so I personally use double quotes and then ". to escape any variable.

<?php
$var = "yes";
echo "Do you like php?<br />".$var;
?>

 

If you use brackets or escape it php knows that variable name and won't waste a ton of resources trying to find a variable that doesn't exist thus it result in echoing it out or fatal error.

 

a fatal error from PHP not finding a variable that matches what's in double quotes?  more like a blank space appearing there.  if you concatenate the variable, what's the point of even using double quotes?  you yourself said that's what it's useful for.

 

<?php
$var = "yes";
echo "Do you like php?<br />$var";
?>

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.