Import Images From mySQL to a Datagrid Table

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Saloko
Posts: 2
Joined: Tue Aug 21, 2018 1:30 pm

Import Images From mySQL to a Datagrid Table

Post by Saloko » Tue Aug 21, 2018 2:04 pm

Hello,

Is there an easy way to import images from mySQL database to a datagrid table?
I want to put images from my database in each row.

I tried it with a code like this:

Code: Select all

put the dgText of group "list" into t
repeat for each line x in t
	set the itemDelimiter to tab
	put item 1 of x into PId
	put "SELECT picture FROM database where id="&PId&"" into sql
	put revQueryDatabase (dbid, sql) into tImageData
	put revDatabaseColumnNamed(tImageData, "picture", theImage)
	set the text of Image "Picture" to theImage
end repeat
The database is connected and I was able to get images from the database. But all images appear in the first row. How can I change that and how can I "connect" the pictures to the other information, so they will change their row while sorting?

Thx for any advice

MaxV
Posts: 1576
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Import Images From mySQL to a Datagrid Table

Post by MaxV » Thu Aug 23, 2018 1:19 pm

Read this guide, it can be in you language, just use the translator on top right.
This guide show how to customize datagrids.
https://livecodeitalia.blogspot.com/201 ... agrid.html

Otherwise you need a datagrid form, and the guide is here: http://lessons.livecode.com/m/datagrid/ ... -grid-form
http://lessons.livecode.com/m/datagrid/ ... -of-people
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Saloko
Posts: 2
Joined: Tue Aug 21, 2018 1:30 pm

Re: Import Images From mySQL to a Datagrid Table

Post by Saloko » Tue Aug 28, 2018 1:20 pm

Thank you, but I already have a datagreed form, that is able to show images.
I only need something to change the line number or something like that, so each image will appear in thr row where it belongs.

MaxV
Posts: 1576
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Import Images From mySQL to a Datagrid Table

Post by MaxV » Tue Aug 28, 2018 4:00 pm

Are you sure that you have a datagrid, with style set to FORM?
If so, you can't use dgText property.
Do yu know how to extract binary data like images from a Database? See https://livecode.wikia.com/wiki/MySQL#W ... h_binaries

Now please follow these steps:
  1. create a datagrid
  2. open the property editor
  3. go to the second page of the property inspector
  4. change style to FORM (first row of second page)
  5. click on ROW TEMPLATE
  6. edit the row template (button in the bottom of the property inspector)
  7. add as many field you need and as many image you need to display in a row
  8. close and save the row template
  9. edit the row behavior code ("edit script"button in the bottom of the property inspector )
  10. edit and add something like:

    Code: Select all

    on FillInData pDataArray
       -- This message is sent when the Data Grid needs to populate
       -- this template with the data from a record. pDataArray is an
       -- an array containing the records data.
       -- You do not need to resize any of your template's controls in
       -- this message. All resizing should be handled in resizeControl.
       
       -- Example:
       set the text of field "firstLabel" of me to pDataArray["label 1"]
       set the text of field "secondLabel" of me to pDataArray["label 2"]
       set the imagedata of image "firstImage" of me to pDataArray["label 3"] #Please note that the Livecode image has to be of the exact dimensions of the image to be inserted. So resize the image and the use the imagedata property.
    end FillInData
Now you can populate the datagrid with:

Code: Select all

put the dgNumberOfRecords of group "list" into temp
repeat with i=1 to List
put revQueryDatabase(connID, "SELECT * FROM images WHERE id=" i  & ";") into tRecordSet
put revDatabaseColumnNamed(tRecordSet, "image", tImage) into tError #tImage contains data
put line i of myTexts1 into theData[i]["label 1"]  #these are already loaded
put line i of myTexts2 into theData[i]["label 2"] #these are already loaded
put tImage into theData[i]["label 3"]
revCloseCursor tRecordSet
set the dgData of group "list" to theData
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Import Images From mySQL to a Datagrid Table

Post by quailcreek » Fri Sep 07, 2018 11:49 pm

Actually you can use dgText to populate a form DG. This is how I do it.

Code: Select all

 put "SELECT FigureID, Condition, theDescription, bCodeNum FROM " & theCollection  & " ORDER by bCodeNum" into tSQLStatement
  put revDataFromQuery(tab,cr, (the uDatabaseID of this stack) ,tSQLStatement) into tData
  put "ID" & tab &"Condition" & tab & "Name" & tab & "bCode" & cr into TheTextData
  set the dgText [true] of grp sTheDataGridName to TheTextData & tData
Tom
MacBook Pro OS Mojave 10.14

Post Reply

Return to “Databases”