How to pupulate mysql data to the combo box

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tanjc
Posts: 16
Joined: Thu Apr 18, 2013 2:44 pm

How to pupulate mysql data to the combo box

Post by tanjc » Fri Feb 28, 2014 11:25 am

Hi,

I need help with the script below. I couldn't get MySQL data into the combo box.
I am not sure whether the problem lies with "put tData into button "button id 1010"

I tested by creating a pushup button to populate tData into a text field, No problem I can see all the data
("put tData into text "field1"), why not working in the combo box. Am I missing something.

I hope some expert could help me. Many thanks.

on menuPick pItemName
global gConnectionID
if gConnectionID is not a number then
answer error "Please connect to the database first."
exit to top
end if

put "a1" into tTableName
put "SELECT `a1`.a1_name FROM a1 " & tTableName 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 label of button "button id 1010"
end if
end menuPick

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: How to pupulate mysql data to the combo box

Post by bangkok » Fri Feb 28, 2014 12:00 pm

Try :

Code: Select all

   set the text of button id 1010 to tData 
(provided that the id of your button is 1010, because it's confusing in your script, you gave a label to your button that looks like a id...)

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

Re: How to pupulate mysql data to the combo box

Post by Simon » Fri Feb 28, 2014 12:16 pm

Hi tanjc,
A combobox needs it's entry's on separate lines.

Code: Select all

 set the label of btn 1 to "Try this" & cr & "I have a" & cr & "pigsbottom"
And yes, what bangkok said.
put tData into label of button "button id 1010"
Normally it's
put tData into label of button id 1010
or
put tData into label of button "myCombobox"

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

tanjc
Posts: 16
Joined: Thu Apr 18, 2013 2:44 pm

Re: How to pupulate mysql data to the combo box

Post by tanjc » Fri Feb 28, 2014 3:44 pm

Hi Bangkok & Simon,

Thanks for your reply. I have tried all the methods you've mentioned above, it still doesn't populate the data into the combo box.

Do I need to make any changes to the Object Inspector (Basic Properties)?

Is there anything wrong with my script?

Regards,
Janet Tan.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to pupulate mysql data to the combo box

Post by Klaus » Fri Feb 28, 2014 3:47 pm

Hi Janet,

it should work! :D
Could you please post your (new) script?


Best

Klaus

P.S.
Do yourself a favour and give your objects (meaningful) names!
Using something like this:
...
button "button id 1234"
...
is asking for trouble :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to pupulate mysql data to the combo box

Post by dunbarx » Fri Feb 28, 2014 4:17 pm

Not quite right.

Try this:

Code: Select all

on mouseUp
put "Try this" & cr & "I have a" & cr & "pigsbottom" into btn "yourCombo"
   end mouseUp
It isn't the label that determines the contents of a menu-style type of button, it is, er, the contents. Buttons are containers, just like fields.

Craig Newman

tanjc
Posts: 16
Joined: Thu Apr 18, 2013 2:44 pm

Re: How to pupulate mysql data to the combo box

Post by tanjc » Fri Feb 28, 2014 4:33 pm

Hi Klaus,

Here's my new script:

on menuPick pItemName
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 "a1" into tTableName -- set this to the name of a table in your database
put "SELECT `a1`.a1_name FROM a1 " & tTableName 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 label of button "a1ComboBox"
-- In Object Inspector (Basic Properties) a1ComboBox is the Name
end if
end menuPick

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to pupulate mysql data to the combo box

Post by Klaus » Fri Feb 28, 2014 4:36 pm

Hi Janet,

as other already pointed out here, "the LABEL of btn xyz" is not the correct "target" for the data!
You need to set the text of that button or just put the data into it:

Code: Select all

...
if item 1 of tData = "revdberr" then
     answer error "There was a problem querying the database:" & cr & tData
  else
     put tData into button "a1ComboBox" 
 end if
...
"the label" is just the "one liner" that shows the currently selected menu item!


Best

Klaus

tanjc
Posts: 16
Joined: Thu Apr 18, 2013 2:44 pm

Re: How to pupulate mysql data to the combo box

Post by tanjc » Fri Feb 28, 2014 5:15 pm

Hi Klaus,

As suggested, I changed the codes to put tData into button "a1ComboBox". When I clicked on the down arrow on the combo box nothing appear but when I created a Push Button and put the same script into the on mouseUp function I can pushed the data into the combo box.

Strange why it doesn't work for the on menuPick function. Am I missing something? I do not want to create a button to push the data into the combo box.

Hope you could help with the above. Thanks.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to pupulate mysql data to the combo box

Post by Klaus » Fri Feb 28, 2014 5:30 pm

Hi Janet,

could please also show us the script of your option menu button?
And are you sure tData is not empty? Sorry, can only guess from afar :D


Best

Klaus

tanjc
Posts: 16
Joined: Thu Apr 18, 2013 2:44 pm

Re: How to pupulate mysql data to the combo box

Post by tanjc » Sat Mar 01, 2014 2:50 am

Hi Klaus,

tData is definitely not empty, otherwise I wouldn't be able to push the data into the combo box using the push button.

The script I showed you earlier is the object script for the combo box button, is this the right place to put this script?

I am not sure what you mean by script for the option menu button. What is the difference between combo box and option menu button? Sorry I am still new to livecode. I think I am missing something here.

Thanks for your patience.

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

Re: How to pupulate mysql data to the combo box

Post by Simon » Sat Mar 01, 2014 3:02 am

Hi Janet,
With a new stack with 1 combobox named "yourCombo" and another button with this script in it

Code: Select all

on mouseUp
   put "Try this" & cr & "I have a" & cr & "pigsbottom" into btn "yourCombo"
end mouseUp
This does work.

Your tData must look like this

Code: Select all

First Entry
Second Entry
I'm the third entry
1 entry per line for each combobox choice.
Does it?

Simon
Edit; this works

Code: Select all

on mouseUp
   put "First Entry" & cr & "Second Entry" & cr & "I'm the third entry" into tData
   set the text of btn "yourCombo" to tData
end mouseUp
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to pupulate mysql data to the combo box

Post by Klaus » Sat Mar 01, 2014 1:06 pm

Hi Janet,
tanjc wrote:I am not sure what you mean by script for the option menu button.
sorry, my fault, I meant of course "combo box".

You could try the following:
Create a field on your card "testfield" and do this:

Code: Select all

...
if item 1 of tData = "revdberr" then
     answer error "There was a problem querying the database:" & cr & tData
  else
     put tData into FIELD "testfield" 
end if
...
then tell us if you see tData in that field.

I have no idea what is going wrong on your side, the syntax is definitively correct:
...
put whatever into btn " a menu button"
...

Best

Klaus

tanjc
Posts: 16
Joined: Thu Apr 18, 2013 2:44 pm

Re: How to pupulate mysql data to the combo box

Post by tanjc » Sat Mar 01, 2014 3:39 pm

Hi Klaus & Simon,

I changed the script of the combo box using the on mouseUp function instead of on menuPick function. The data was populated into the combo box now.

Thanks all for your help.

Post Reply