Jump to content

[SOLVED] Retriving information for an image


perrij3

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

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.