monkeytooth Posted August 22, 2008 Share Posted August 22, 2008 $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? Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/ Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 WHERE goes before the LIMIT clause. have a look at the MySQL manual on the SELECT syntax - it will show you the order in which clauses must appear if they are to be used. Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623193 Share on other sites More sharing options...
Maq Posted August 22, 2008 Share Posted August 22, 2008 Also shouldn't " WHERE c0unty = '$clocd' "; be " WHERE c0unty = '.$clocd.' "; ? Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623196 Share on other sites More sharing options...
revraz Posted August 22, 2008 Share Posted August 22, 2008 No Also shouldn't " WHERE c0unty = '$clocd' "; be " WHERE c0unty = '.$clocd.' "; ? Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623197 Share on other sites More sharing options...
cooldude832 Posted August 22, 2008 Share Posted August 22, 2008 If you are going to connotation methods (which I recommend) you need to show it right <?php $query = " SELECT * FROM `memb_pers` Where C0unty = '".$cloucd."' LIMIT ".$offset.", ".$clocd; ?> Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623206 Share on other sites More sharing options...
monkeytooth Posted August 22, 2008 Author Share Posted August 22, 2008 Thank you all.. yet again you have help me.. Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623211 Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 If you are going to connotation methods (which I recommend) you need to show it right i believe what you mean are concatenation methods (in case anyone ever goes to google it). Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623247 Share on other sites More sharing options...
Prismatic Posted August 22, 2008 Share Posted August 22, 2008 You can also use brackets to concate $name = "Bob"; echo "Hello my name is {$name}"; versus $name = "Bob"; echo "Hello my name is ". $name; Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623257 Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623264 Share on other sites More sharing options...
Daniel0 Posted August 22, 2008 Share Posted August 22, 2008 Regarding the single/double quote thing. http://phpbench.com indicates that there is no difference. Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623276 Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623281 Share on other sites More sharing options...
Daniel0 Posted August 22, 2008 Share Posted August 22, 2008 Well it would make sense that it would be like that. I guess they made some sort of optimizations to deal with that. Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623283 Share on other sites More sharing options...
cooldude832 Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623297 Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623300 Share on other sites More sharing options...
cooldude832 Posted August 22, 2008 Share Posted August 22, 2008 its more of the pretty print pick up in the notepad editor because I can tell where a var is and where a string is very easily Quote Link to comment https://forums.phpfreaks.com/topic/120900-solved-whats-wrong-with-this-php-mysql-syntax/#findComment-623304 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.