jakebur01 Posted May 28, 2008 Share Posted May 28, 2008 I am having trouble making this work. I am trying to select a row if any of the three columns matches $breed. $result3 = mysql_query("SELECT * FROM dog_account WHERE primary = '$breed' or secondary = '$breed' or third = '$breed' ", $db) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/107642-trouble-with-select-statement/ Share on other sites More sharing options...
ILYAS415 Posted May 28, 2008 Share Posted May 28, 2008 what actually happens? Quote Link to comment https://forums.phpfreaks.com/topic/107642-trouble-with-select-statement/#findComment-551788 Share on other sites More sharing options...
jakebur01 Posted May 28, 2008 Author Share Posted May 28, 2008 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 'primary = '111' or secondary = '111' or third = '111'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/107642-trouble-with-select-statement/#findComment-551790 Share on other sites More sharing options...
BlueSkyIS Posted May 28, 2008 Share Posted May 28, 2008 primary is a MySQL reserved word. you shouldn't use it as a column name. Quote Link to comment https://forums.phpfreaks.com/topic/107642-trouble-with-select-statement/#findComment-551792 Share on other sites More sharing options...
jakebur01 Posted May 28, 2008 Author Share Posted May 28, 2008 That got it! Thank you!! Quote Link to comment https://forums.phpfreaks.com/topic/107642-trouble-with-select-statement/#findComment-551796 Share on other sites More sharing options...
gizmola Posted May 28, 2008 Share Posted May 28, 2008 With that said you can use reserved words as column names, but you have to enclose them like so: `primary`. Now to the bigger question --- your table structure has implemented the classic repeating group (primary, secondary, third) which I assume from the example is a foreign key to a Breed table. Really that should be a many to many. Tables should be dog_account, breed, dog_breed, where dog_breed is something like: (dog_id, breed_id, percent). Then you wouldn't have to construct ugly or queries like the one you're doing now. Quote Link to comment https://forums.phpfreaks.com/topic/107642-trouble-with-select-statement/#findComment-551827 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.