I'm working with getting info from a MySQL to show up in a card. That part is working. However, I have 2 separate scripts. One to open the database and one to put the data into a field. Can these two below be combined? The first one is the opening the database. The second one is to put the data into a field.
on mouseUp 
    -- use a global variable to hold the connection ID so other scripts can use it 
    global gConnectionID 
    -- set up the connection parameters - edit these to suit your database 
    put "mysql" into theDBType 
   put "XXXXXXXXXXX" into theDBHost 
   put "XXXXXXXXXXX" into theDBName 
   put "XXXXXXXXXXX" into theDBUser 
   put "XXXXXXXXXXX" into theDBPassword 
   put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into tResult 
    -- check if it worked and display an error message if it didn't 
    -- & set the connection ID global 
    if tResult is a number then 
        put tResult into gConnectionID 
    else 
        put empty into gConnectionID 
        answer error "Unable to connect to the database:" & cr & tResult 
     end if 
     go to card 4 
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
    
    -- construct the SQL (this selects all the data from the specified table) 
    put "content" into tTableName    -- set this to the name of a table in your database
    put "SELECT content_body FROM content WHERE `content_name` = '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
        set the HTMLText of field "schedule" to tData
    end if
end mouseUp
			
			
									
									
						Combining 2 scripts
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Combining 2 scripts
Hi Ron,
like this:
Best
Klaus
			
			
									
									
						like this:
Code: Select all
on mouseUp 
   -- use a global variable to hold the connection ID so other scripts can use it 
   global gConnectionID 
   
   -- set up the connection parameters - edit these to suit your database 
   put "mysql" into theDBType 
   put "XXXXXXXXXXX" into theDBHost 
   put "XXXXXXXXXXX" into theDBName 
   put "XXXXXXXXXXX" into theDBUser 
   put "XXXXXXXXXXX" into theDBPassword 
   put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into tResult 
   
   -- check if it worked and display an error message if it didn't 
   -- & set the connection ID global 
   if tResult is a number then 
      put tResult into gConnectionID 
   else 
      put empty into gConnectionID 
      answer error "Unable to connect to the database:" & cr & tResult 
      exit to top
   end if 
   
   -- construct the SQL (this selects all the data from the specified table) 
   put "content" into tTableName    -- set this to the name of a table in your database
   put "SELECT content_body FROM content WHERE `content_name` = '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
      exit to top
   else
     ## I presume that this field is on Card 4, right?
      set the HTMLText of field "schedule" OF CD 4 to tData
   end if
   go to card 4 
end mouseUp Klaus
- 
				ronniebellie
- Posts: 28
- Joined: Fri Jun 26, 2015 6:17 pm
Re: Combining 2 scripts
Thank you very much! That worked.