perrij3 Posted August 10, 2009 Share Posted August 10, 2009 I am trying to get the image I set as default with the following code. $sql4 = "SELECT * FROM image WHERE FK_OB_ID = $Obituary_ID AND Default = 1"; $result4 = mysql_query($sql4)or die (mysql_error()); $photo = mysql_fetch_assoc($result4); } } The area that I am having the problem with is the AND Default = 1 line. When I take it out, it works fine for now. I only have one image for the Obituary_ID set, so there is only one image that it can retrieve. When I add the AND Default = 1, I get the following error message, 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 '= 1' at line 3. Could someone please let me know what I am doing wrong? Thanks for any help you can offer. Quote Link to comment https://forums.phpfreaks.com/topic/169531-solved-retriving-information-for-an-image/ Share on other sites More sharing options...
Maknis Posted August 10, 2009 Share Posted August 10, 2009 Maybe.. $sql4 = 'SELECT * FROM image WHERE FK_OB_ID = "$Obituary_ID" AND default = 1'; I am trying to get the image I set as default with the following code. $sql4 = "SELECT * FROM image WHERE FK_OB_ID = $Obituary_ID AND Default = 1"; $result4 = mysql_query($sql4)or die (mysql_error()); $photo = mysql_fetch_assoc($result4); } } The area that I am having the problem with is the AND Default = 1 line. When I take it out, it works fine for now. I only have one image for the Obituary_ID set, so there is only one image that it can retrieve. When I add the AND Default = 1, I get the following error message, 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 '= 1' at line 3. Could someone please let me know what I am doing wrong? Thanks for any help you can offer. Quote Link to comment https://forums.phpfreaks.com/topic/169531-solved-retriving-information-for-an-image/#findComment-894500 Share on other sites More sharing options...
perrij3 Posted August 10, 2009 Author Share Posted August 10, 2009 I gave that a try and still the same error message. Quote Link to comment https://forums.phpfreaks.com/topic/169531-solved-retriving-information-for-an-image/#findComment-894504 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 check the fields in your mysql, try to run your sql directly from mysql and see the result. Do this $sql4 = "SELECT * FROM image WHERE FK_OB_ID = $Obituary_ID AND `Default` = 1"; Check the case in Default, because the word Default is kind of reserved for mysql you need to clarify it like using order as one of your field. Use `Default` = 1 and see what will happen. Quote Link to comment https://forums.phpfreaks.com/topic/169531-solved-retriving-information-for-an-image/#findComment-894510 Share on other sites More sharing options...
perrij3 Posted August 10, 2009 Author Share Posted August 10, 2009 Ok, I figured out the issue. I had Default set to a TinyInt in my Database. I changed it to a Int and it worked. Not sure why this would make a difference, but it did. I am only save a 0 or 1 there. Would a Bool be better to use instead of a Int. I can only have 1 default image per person. Quote Link to comment https://forums.phpfreaks.com/topic/169531-solved-retriving-information-for-an-image/#findComment-894527 Share on other sites More sharing options...
halfman Posted August 10, 2009 Share Posted August 10, 2009 Ok, I figured out the issue. I had Default set to a TinyInt in my Database. I changed it to a Int and it worked. Not sure why this would make a difference, but it did. I am only save a 0 or 1 there. Would a Bool be better to use instead of a Int. I can only have 1 default image per person. use SET if you have a 0 or 1 value or 'yes','no' - it takes less memory, Type will be SET, and Value will be '1','0' and default value will be 1 OR Type will be SET, and Value will be 'Y','N' and default value will be Y Check this document: http://www.vbmysql.com/articles/mysql/the-mysql-set-datatype Quote Link to comment https://forums.phpfreaks.com/topic/169531-solved-retriving-information-for-an-image/#findComment-894531 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.