Page 1 of 1

Show MySQL data in a field

Posted: Fri Jul 10, 2015 6:55 pm
by ronniebellie
On my LC card, I have a good connection to MySQL data on my server. I want to show the data from the connection in a field on the card. Here's my script, but it's not working. An error message is saying "error at line 11 ... char 9" My table name is "content" and my query seem correct. The field on my card it titled "schedule". Any ideas what's going on?

on mouseUp
    -- check the global connection ID to make sure we have a database connection
    global gConnectionID
    if gConnectionID is not a number then
        answer error "Please connect to the database first."
        exit to top
    end if
    
    put "content" into tTableName
    put "SELECT * FROM content WHERE `content_name` LIKE 'schedule'") into tSQL
    
    -- query the database
    put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
    
    -- check the result and display the data or an error message
    if item 1 of tData = "revdberr" then
        answer error "There was a problem querying the database:" & cr & tData
    else
        put tData into field "schedule"
    end if
end mouseUp

Re: Show MySQL data in a field

Posted: Fri Jul 10, 2015 8:19 pm
by phaworth
This is a compile error, correct? Which is line 11 in your script and what's the rest of the error message?

Not related to your problem but Couple of other things to watch out for.

I think your error check should be "if word 1 of tData..." not "if item1 of tData..."

The SELECT should work just fine, but it might work faster if you used "='schedule'" since the LIKE has no wildcard characters in it.

Pete

Re: Show MySQL data in a field

Posted: Fri Jul 10, 2015 10:15 pm
by Klaus
Hi Ronnie,

there is an orphaned trailing bracket! 8)
...
### put "SELECT * FROM content WHERE `content_name` LIKE 'schedule'") into tSQL
put "SELECT * FROM content WHERE 'content_name' LIKE 'schedule'" into tSQL
...

Best

Klaus

Re: Show MySQL data in a field

Posted: Mon Jul 13, 2015 4:54 pm
by ronniebellie
Thanks both of you for your input. But now I have another problem. I had saved and closed my stack on Friday, but now when I try to open it, it says "There was a problem opening that stack" stack is corrupted. check for backup file." Unfortunately, I'm on the road the last 6 weeks and don't have a backup. My bad.

However, the good news is that I saved several of the most important scripts in another place in this forum, so I think redoing it will only take 3 hours or so.

Before I go there, any advice on how to open my corrupted stack?

Re: Show MySQL data in a field

Posted: Mon Jul 13, 2015 5:17 pm
by phaworth
See if there is a file with the same name as your stack file but with a "~" character at the start in the same folder as the original stack. If so, try opening it..

Another thing that can happen is if the stack was saved with LC v7 and then you try to open it with LC v6 or earlier, this message is displayed.

Pete

Re: Show MySQL data in a field

Posted: Mon Jul 13, 2015 5:34 pm
by ronniebellie
There no file with a with a "~" character at the start in that folder. However, I found an old LC stack that I had save most of my scripts in, so I should be okay with rebuilding it. Thanks for all your help.

Ron

Re: Show MySQL data in a field

Posted: Mon Jul 13, 2015 5:39 pm
by Klaus
Hi Ron,

you can also try to open that stack in a TEXT editor and read most, if not all of the scripts!


Best

Klaus