Page 1 of 1

Table For Image Pointers

Posted: Fri Dec 09, 2011 11:41 pm
by nbasso713
I'm relatively new to using sql to give you guys a heads up. I need to create a table that will store the pointer of an image that i've uploaded on my site. Eventually i'd like to be able to call a random image from the database and have the image displayed on it's own unique page.

I plan on renaming the images to incremented numbers, by just adding 1 to the highest id in the table that i'm trying to create.

I'm not really sure what should be in the table and what i'll need to specifically enter to create a new table. I think i'll be able to get away w/ the id, name, and pointer. But i'm not exactly sure what data type is required for the pointer.

Would this be correct?

CREATE TABLE uploaded_images (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
PRIMARY KEY(id)
);

Based on that table would this be correct for the insert in my php? (assuming "rofl" is the image directory)

mysql_query("INSERT INTO uploaded_images (image_url)VALUES('rofl/".$_FILES["image"]["name"]."')") or die(mysql_error());

All help is greatly appreciate.

Re: Table For Image Pointers

Posted: Sat Dec 10, 2011 9:29 am
by nbasso713
I think i got it for the most part. I was able to create the table and the insert function was easy enough to figure out. What i'm working on now is retrieving the max id from the table.

Re: Table For Image Pointers

Posted: Sat Dec 10, 2011 11:07 am
by nbasso713
Sweet I figured out how to do this and increment my next upload based on the maxid. The next thing I need to figure out is how to call a random image from the table to be display on it's own unique url. Such as, "mydomain.com/id=1" or something like that which will place the image as a specific url.