Show MySQL data in a field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Show MySQL data in a field
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
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
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
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
Hi Ronnie,
there is an orphaned trailing bracket!
...
### put "SELECT * FROM content WHERE `content_name` LIKE 'schedule'") into tSQL
put "SELECT * FROM content WHERE 'content_name' LIKE 'schedule'" into tSQL
...
Best
Klaus
there is an orphaned trailing bracket!
...
### put "SELECT * FROM content WHERE `content_name` LIKE 'schedule'") into tSQL
put "SELECT * FROM content WHERE 'content_name' LIKE 'schedule'" into tSQL
...
Best
Klaus
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Re: Show MySQL data in a field
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?
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
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
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
-
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Re: Show MySQL data in a field
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
Ron
Re: Show MySQL data in a field
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
you can also try to open that stack in a TEXT editor and read most, if not all of the scripts!
Best
Klaus