Functionality of MySQL records showing in a data grid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Functionality of MySQL records showing in a data grid
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?
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?
Re: Functionality of MySQL records showing in a data grid
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
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
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Re: Functionality of MySQL records showing in a data grid
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.
Re: Functionality of MySQL records showing in a data grid
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
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
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Re: Functionality of MySQL records showing in a data grid
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
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
Re: Functionality of MySQL records showing in a data grid
Hi ronniebelle,
add a Carriage Return (CR) where neccessary!
...
answer theDataA["pres_title"] & CR & theDataA["summary"] & CR & theDataA["fname"] & CR & theDataA["lname"]
...
Best
Klaus
add a Carriage Return (CR) where neccessary!
...
answer theDataA["pres_title"] & CR & theDataA["summary"] & CR & theDataA["fname"] & CR & theDataA["lname"]
...
Best
Klaus
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Re: Functionality of MySQL records showing in a data grid
Thanks for your help. How do I do a double line break?
Re: Functionality of MySQL records showing in a data grid
Just add another CR:
...
answer theDataA["pres_title"] & CR & CR & theDataA["summary"]
...
...
answer theDataA["pres_title"] & CR & CR & theDataA["summary"]
...
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Re: Functionality of MySQL records showing in a data grid
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
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
Re: Functionality of MySQL records showing in a data grid
Hi Ronnie,
you can put any data anywhere in Livecode as long as you put the correct "address" on them
Example, you put the complete info into ONE field of another card (instead of ANSWERing it):
Or if you want to put the info into separate field on another card:
You get the picture!
HINT!
Give your objects a meaningful name!
"Field 1" is erm. suboptimal...
Best
Klaus
you can put any data anywhere in Livecode as long as you put the correct "address" on them
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
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"
...
HINT!
Give your objects a meaningful name!
"Field 1" is erm. suboptimal...
Best
Klaus
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Re: Functionality of MySQL records showing in a data grid
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?
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?
Re: Functionality of MySQL records showing in a data grid
Sorry, no capisce!?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?