Page 1 of 1

Load Image From MySQL Database

Posted: Thu Mar 31, 2016 9:16 am
by bbhank
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.

:?

Re: Load Image From MySQL Database

Posted: Thu Mar 31, 2016 11:57 am
by FourthWorld
See the & operator.

Re: Load Image From MySQL Database

Posted: Thu Mar 31, 2016 1:17 pm
by bbhank
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:

Re: Load Image From MySQL Database

Posted: Thu Mar 31, 2016 4:30 pm
by FourthWorld
"&" 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

Re: Load Image From MySQL Database

Posted: Thu Mar 31, 2016 4:44 pm
by bbhank
OK. Thank you. That looks like it will work.

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

Re: Load Image From MySQL Database

Posted: Fri Apr 01, 2016 8:35 pm
by jacque
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

Re: Load Image From MySQL Database

Posted: Sat Apr 02, 2016 5:20 pm
by bbhank
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