Show MySQL data in a field

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

Show MySQL data in a field

Post by ronniebellie » Fri Jul 10, 2015 6:55 pm

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

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

Re: Show MySQL data in a field

Post by phaworth » Fri Jul 10, 2015 8:19 pm

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

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

Re: Show MySQL data in a field

Post by Klaus » Fri Jul 10, 2015 10:15 pm

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

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

Re: Show MySQL data in a field

Post by ronniebellie » Mon Jul 13, 2015 4:54 pm

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?

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

Re: Show MySQL data in a field

Post by phaworth » Mon Jul 13, 2015 5:17 pm

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

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

Re: Show MySQL data in a field

Post by ronniebellie » Mon Jul 13, 2015 5:34 pm

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

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

Re: Show MySQL data in a field

Post by Klaus » Mon Jul 13, 2015 5:39 pm

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

Post Reply

Return to “Databases”