Functionality of MySQL records showing in a data grid

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ronniebellie
Posts: 28
Joined: Fri Jun 26, 2015 6:17 pm

Functionality of MySQL records showing in a data grid

Post by ronniebellie » Sat Jun 27, 2015 6:13 pm

I'm a new comer to Livecode and have spent the last 4 days figuring out how to connect my Livecode app to a MySQL database and then display some of the results of that data in a Livecode data grid. I'm working on an educational conference (2 days long) that will be held in October of this year with about 800 attendees. There will be about 200 presentations and workshops. The presentation info is in a MySQL database and includes info such as name, institution, presentation title, presentations summary, biography, intended audience, topics addressed, etc.

I am having some success. The database connection is working fine. I am able to show certain data fields (short ones such as first name, last name, presentation title, room and time) in columns in a datagrid. Unfortunately, with the longer fields such as presentation summary, the info in the column does not wrap and it's one long horizontal line of about 35 words, so I have to exclude those fields from showing in the data grid. What I want to do now is take it to the next step and be able to click on a presentation title in the data grid and and then for it to show more info about that particular presentation on another card such as presentation summary, biography, audience, topics addressed, etc. I don't even know where to begin with such a task. Can each record that shows in in a data grid have its own script?

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Functionality of MySQL records showing in a data grid

Post by phaworth » Sat Jun 27, 2015 8:04 pm

The datagrid library sends a selectionChanged message to your datagrid when you click on a line in it. Write a selectionChanged handler in your datagrid group's script to get the contents of the line and put them into whatever controls you want. For example:

on selectionChanged pHilitedIndex, pPrevHilitedIndex
put the dgDataOfIndex [ pHilitedIndex ] of me into theDataA
--do what you need with the contents of the datagrid row here. theDataA will be an array keyed by datagrid column name
end selectionChanged

Another option would be to use a datagrid form instead of a table (see the datagrid manual for details).

Pete

ronniebellie
Posts: 28
Joined: Fri Jun 26, 2015 6:17 pm

Re: Functionality of MySQL records showing in a data grid

Post by ronniebellie » Tue Jun 30, 2015 12:15 am

Thanks for the advice. I've switched it to a data grid form and the MySQL is connecting. I know that because the data from the database is showing up, although it can only be seen in the Property Inspector under the show the content option. When I'm in the non-edit mode, the data is not showing in the data grid at all. It's blank.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Functionality of MySQL records showing in a data grid

Post by phaworth » Tue Jun 30, 2015 3:16 am

How are you loading the data into the database? Using a datagrid form introduces another level of complexity in that it's your responsibility to load the data from the dgData array into the controls in the datagrid.

Rather than me try to explain it here, take a look at section 2.5 of the Datagrid Manual to see how to do this. If you don't have the Datagrid manual, go to http://lessons.runrev.com/m/datagrid and take a look at the section titled "How DO I Customize A Form's Row Template"

Pete

ronniebellie
Posts: 28
Joined: Fri Jun 26, 2015 6:17 pm

Re: Functionality of MySQL records showing in a data grid

Post by ronniebellie » Tue Jul 07, 2015 6:20 pm

Okay. Your advice is working. I'm checking the manual and have made some headway. I'm using the dgHilitedLines property to get the data associated with a selected row in my data grid to show up in an answer dialogue with the info I need. However, how do I get the info in the answer dialogue to have line breaks, so I can have the title on one line, then the summary, then fname, lname, then biography and so on? I'm pasting my data grid script below.

on mouseUp pBtnNum
    if pBtnNum is 1 then
        put the dgHilitedLines of group "DataGrid 1" into theLine
        put the dgDataOfLine[theLine] of group "DataGrid 1" into theDataA
        answer theDataA["pres_title"] && theDataA["summary"] && theDataA["fname"] && theDataA["lname"]
    end if
end mouseUp

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Functionality of MySQL records showing in a data grid

Post by Klaus » Tue Jul 07, 2015 6:26 pm

Hi ronniebelle,

add a Carriage Return (CR) where neccessary! :D
...
answer theDataA["pres_title"] & CR & theDataA["summary"] & CR & theDataA["fname"] & CR & theDataA["lname"]
...

Best

Klaus

ronniebellie
Posts: 28
Joined: Fri Jun 26, 2015 6:17 pm

Re: Functionality of MySQL records showing in a data grid

Post by ronniebellie » Tue Jul 07, 2015 6:35 pm

Thanks for your help. How do I do a double line break?

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Functionality of MySQL records showing in a data grid

Post by Klaus » Tue Jul 07, 2015 6:37 pm

Just add another CR:
...
answer theDataA["pres_title"] & CR & CR & theDataA["summary"]
... :D

ronniebellie
Posts: 28
Joined: Fri Jun 26, 2015 6:17 pm

Re: Functionality of MySQL records showing in a data grid

Post by ronniebellie » Wed Jul 08, 2015 5:07 pm

You've been very helpful. Thank you. The data is showing fine in an answer dialogue. However, I would like the data (which is a lot) to show up in another card (titled "Show data") that has a text entry field titled "Field 1". This way I can enlarge and format the text area which is showing the data from the MySQL.

Here's my script that is working for the answer dialogue.

on mouseUp pBtnNum
    if pBtnNum is 1 then
        put the dgHilitedLines of group "DataGrid 1" into theLine
        put the dgDataOfLine[theLine] of group "DataGrid 1" into theDataA
        answer theDataA["fname"] && theDataA["lname"] & CR & CR & theDataA["copresenters"] & CR & CR & theDataA["pres_title"] & CR & CR & theDataA["summary"] & CR & CR & theDataA["biography"]
    end if
end mouseUp

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Functionality of MySQL records showing in a data grid

Post by Klaus » Wed Jul 08, 2015 5:16 pm

Hi Ronnie,

you can put any data anywhere in Livecode as long as you put the correct "address" on them :D
Example, you put the complete info into ONE field of another card (instead of ANSWERing it):

Code: Select all

on mouseUp pBtnNum
    if pBtnNum is 1 then
        put the dgHilitedLines of group "DataGrid 1" into theLine
        put the dgDataOfLine[theLine] of group "DataGrid 1" into theDataA

       ## Fill field on other card here:
        put theDataA["fname"] && theDataA["lname"] & CR & CR & theDataA["copresenters"] & CR & CR & theDataA["pres_title"] & CR & CR & \
             theDataA["summary"] & CR & CR & theDataA["biography"] into fld "Field 1" of cd "the other card"
    
       ## Then go to the other card (optional)
       go cd " the other card"
    end if
end mouseUp
Or if you want to put the info into separate field on another card:

Code: Select all

...
put theDataA["fname"] into fld "fname" of cd "the other card"
put theDataA["lname"]  into fld "lname" of cd "the other card"
## etc..
go cd " the other card"
...
You get the picture!

HINT!
Give your objects a meaningful name!
"Field 1" is erm. suboptimal... :D


Best

Klaus

ronniebellie
Posts: 28
Joined: Fri Jun 26, 2015 6:17 pm

Re: Functionality of MySQL records showing in a data grid

Post by ronniebellie » Wed Jul 08, 2015 5:54 pm

It's working very well. Thanks for your advice.

Another question. How can I put labels in the script so something like pres_title has a label called "Title" for the viewers of the data?

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Functionality of MySQL records showing in a data grid

Post by Klaus » Wed Jul 08, 2015 6:03 pm

ronniebellie wrote:How can I put labels in the script so something like pres_title has a label called "Title" for the viewers of the data?
Sorry, no capisce!? :shock:

Post Reply

Return to “Databases”