How to pupulate mysql data to the combo box
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How to pupulate mysql data to the combo box
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
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
Re: How to pupulate mysql data to the combo box
Try :
(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...)
Code: Select all
set the text of button id 1010 to tData
Re: How to pupulate mysql data to the combo box
Hi tanjc,
A combobox needs it's entry's on separate lines.
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
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"
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!
Re: How to pupulate mysql data to the combo box
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.
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.
Re: How to pupulate mysql data to the combo box
Hi Janet,
it should work!
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
it should work!

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

Re: How to pupulate mysql data to the combo box
Not quite right.
Try this:
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
Try this:
Code: Select all
on mouseUp
put "Try this" & cr & "I have a" & cr & "pigsbottom" into btn "yourCombo"
end mouseUp
Craig Newman
Re: How to pupulate mysql data to the combo box
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
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
Re: How to pupulate mysql data to the combo box
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:
"the label" is just the "one liner" that shows the currently selected menu item!
Best
Klaus
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
...
Best
Klaus
Re: How to pupulate mysql data to the combo box
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.
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.
Re: How to pupulate mysql data to the combo box
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
Best
Klaus
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

Best
Klaus
Re: How to pupulate mysql data to the combo box
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.
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.
Re: How to pupulate mysql data to the combo box
Hi Janet,
With a new stack with 1 combobox named "yourCombo" and another button with this script in it
This does work.
Your tData must look like this
1 entry per line for each combobox choice.
Does it?
Simon
Edit; this works
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
Your tData must look like this
Code: Select all
First Entry
Second Entry
I'm the third entry
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!
Re: How to pupulate mysql data to the combo box
Hi Janet,
You could try the following:
Create a field on your card "testfield" and do this:
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
sorry, my fault, I meant of course "combo box".tanjc wrote:I am not sure what you mean by script for the option menu button.
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
...
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
Re: How to pupulate mysql data to the combo box
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.
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.