Having a tough time with Data Grid Forms + MySQL

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
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Having a tough time with Data Grid Forms + MySQL

Post by shawnblc » Wed May 21, 2014 2:16 am

I'm having a tough time with Data Grid Forms + MySQL. It seems like I get close, but not close enough. Does anyone have a sample data grid forms + mysql link or have a demo on their server? I've viewed the tutorials I found on the LiveCode website, but surely somewhere there's on that combines data grid forms and mysql. Been trying this all day. lol.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Having a tough time with Data Grid Forms + MySQL

Post by Simon » Wed May 21, 2014 2:44 am

Hi Shawn,
You have used this example:
http://lessons.runrev.com/m/4071/l/3051 ... e-database
Changing that over to mysql is not hard, just have to set it up right.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Having a tough time with Data Grid Forms + MySQL

Post by shawnblc » Wed May 21, 2014 3:13 am

I'll give that one another shot. I'm not having any problems connecting to the database though, in fact even once I was pulling data from the database, but it wasn't aligned according to the data grid form template. I'm close, but still not there.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Having a tough time with Data Grid Forms + MySQL

Post by Simon » Wed May 21, 2014 3:24 am

I guess this one is more appropriate;
http://lessons.runrev.com/m/4071/l/7003 ... l-database
but the last time I did it (months ago) there was a problem with;

Code: Select all

    put "runrev.com" into tDatabaseAddress
    put "runrev_test" into tDatabaseName
    put "runrev_example" into tDatabaseUser
    put "example" into tDatabasePassword
I think I fixed it by changing
put "runrev_example" into tDatabaseUser
to
put "runrev_test" into tDatabaseUser
Or maybe it was the line above to change to "..._example"

Simon
Edit: I think they fixed it because it was this lesson which used to be different in those names:
http://lessons.runrev.com/m/4071/l/1659 ... grid-array
Wait a sec! That is the lesson you want.
Last edited by Simon on Wed May 21, 2014 3:32 am, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Having a tough time with Data Grid Forms + MySQL

Post by shawnblc » Wed May 21, 2014 3:31 am

Like I mentioned above I was pulling data, but it wasn't aligning right in the data grid form template. I edited it, and now I'm not pulling any data. Still have a good db connection.

I think this is where I'm making my errors.

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 "Label" of me to pDataArray["label 1"]
    
    set the text of fld "lblDate" of me to pDataArray["date"]
    set the text of fld "lblTitle" of me to pDataArray["title"]
    set the text of fld "lblMessage" of me to pDataArray["message"]
end FillInData

Code: Select all

on LayoutControl pControlRect
    local theFieldRect
    
    -- This message is sent when you should layout your template's controls.
    -- This is where you resize the 'Background' graphic, resize fields and 
    -- position objects.
    -- For fixed height data grid forms you can use items 1 through 4 of pControlRect as
    -- boundaries for laying out your controls.
    -- For variable height data grid forms you can use items 1 through 3 of pControlRect as
    -- boundaries, expanding the height of your control as needed.
        
    -- Example:
    --put the rect of field "Label" of me into theFieldRect
    put item 3 of pControlRect - 5 into item 3 of theFieldRect
    --set the rect of field "Label" of me to theFieldRect
    
    put the rect of fld "lblDate" of me into theFieldRect
    put the rect of fld "lblTitle" of me into theFieldRect
    put the rect of fld "lblMessage" of me into theFieldRect
    
    set the rect of fld "lblDate" of me to theFieldRect
    set the rect of fld "lblTitle" of me to theFieldRect
    set the rect of fld "lblMessage" of me to theFieldRect
    
    set the rect of graphic "Background" of me to pControlRect
end LayoutControl


Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Having a tough time with Data Grid Forms + MySQL

Post by Simon » Wed May 21, 2014 3:41 am

ooops they should be interspersed

Code: Select all

 put the rect of fld "lblDate" of me into theFieldRect
 set the rect of fld "lblDate" of me to theFieldRect
put the rect of fld "lblTitle" of me into theFieldRect
 set the rect of fld "lblTitle" of me to theFieldRect
put the rect of fld "lblMessage" of me into theFieldRect
set the rect of fld "lblMessage" of me to theFieldRect
otherwise they all end in the same location

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Having a tough time with Data Grid Forms + MySQL

Post by shawnblc » Wed May 21, 2014 4:02 am

Let me try that Simon. I'll update. Thank you.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Having a tough time with Data Grid Forms + MySQL

Post by shawnblc » Wed May 21, 2014 4:10 am

Pulling data again Simon! You're the man! Now let me tweak my SQL statements and continue playing around with it. Thank you Simon! These data grids will give you headache!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Having a tough time with Data Grid Forms + MySQL

Post by Simon » Wed May 21, 2014 4:26 am

Hi Shawn,
Yeah, DataGrids should come with a warning label! :)

Glad you got it working.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: Having a tough time with Data Grid Forms + MySQL

Post by shawnblc » Wed May 21, 2014 4:54 am

Simon, quick question if you're still around. If I want to have replies to messages, I'd need another template or would I modify the current template? In the meantime I'll try it out.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Having a tough time with Data Grid Forms + MySQL

Post by Simon » Wed May 21, 2014 5:05 am

hi Shawn,
I think you'd use another table because there may be many replies and "inner join;
http://www.w3schools.com/sql/sql_join_inner.asp
Bookmark that.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply