Load Image From MySQL Database

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Load Image From MySQL Database

Post by bbhank » Thu Mar 31, 2016 9:16 am

Needing to load images into DataGrid from MySQL database as needed.
I have written a query that gets the ID of the needed image. The required image is not in the table. The actual image is in a folder. The table only contains the names of the image and not their locations. The rest of the location needs to be prepended(appended to the front of) the name from the database.

My problem is how to load the needed image and have it appear in the DataGrid.

:?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Load Image From MySQL Database

Post by FourthWorld » Thu Mar 31, 2016 11:57 am

See the & operator.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Load Image From MySQL Database

Post by bbhank » Thu Mar 31, 2016 1:17 pm

I did. Plus went to the samples and tutorials without finding anything like this.

Here's what needs to happen: An image in a DataGrid field needs to change according to the id of the listing. The data for the listing is taken from multiple tables in one database. The table that references the images only has the name and not the location of the images. The tables are linked by their numbers. The images themselves are kept in an actual folder and are often changed and/or added to.

:roll:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Load Image From MySQL Database

Post by FourthWorld » Thu Mar 31, 2016 4:30 pm

"&" is LiveCode's concatenation operator. I'm not familiar with tutorials on it, but since you have two things (path and file name) that need to be concatenated it seems a good fit.

Code: Select all

put "/home/user/me/somefolder/images" into tPath
put "123456.jpg" into tFileName
put tPath &"/"& tFileName into tFullPath
set the filename of image "MyImageDisplayObject" to tFullPath
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Load Image From MySQL Database

Post by bbhank » Thu Mar 31, 2016 4:44 pm

OK. Thank you. That looks like it will work.

Let me get the image to load from the id tho.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Load Image From MySQL Database

Post by jacque » Fri Apr 01, 2016 8:35 pm

It is easier to give the image object a name and refer to it that way. Then you don't need to mess around with IDs:

Code: Select all

set the filename of image "userPhoto" of me to tFullPath
Or you can refer to it by number:

Code: Select all

set the filename of image 1 of me to tFullPath
But if you really want to use your ID function (which seems like too much work and overhead to me, but...)

Code: Select all

set the filename of image ID tID of me to tFullPath
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Load Image From MySQL Database

Post by bbhank » Sat Apr 02, 2016 5:20 pm

Thanks.

I'm using the category ID number to match the event ID with the category ID. There is a different image associated with each category ID number. They are not in the same table. Looking at the DataGrid Tutorials and other stuff. Brigham Young University seems to have a lot of info also.

:D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”