Jump to content

Recommended Posts

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.

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.

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.

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.