proper communication between 2 web listboxes

Hello guys, just need a little help about the proper communication between 2 web listboxes.


Tables/data that needs to be fetched from the database:

*Listbox #1 -> Table #1
D_code, randomdata1

*Listbox #2 -> Table #2
B_code, D_code, randomdata1,randomdata2,randomdata3,randomdata4,random5

*D_code from Listbox#1 is the same with Listbox2,
*There is only one unique D_code in ListBox1 but there are duplicates in ListBox2


What i wanted to happen when the webpage load/shown:

*Listbox #1 will fetch the data of table #1 from the database, but Listbox #2 will be empty/or will not show anything by default. (of course this is easy)

The main task is:
*If a user select a single row in Listbox #1, then ListBox #2 will only fetch data with the same D_code of the selected row in ListBox1.

For example ListBox1 fetched these data:
–Listbox1–
D_code1 | RandomData1 -> selected
D_code2 | RandomData2
D_code3 | RandomData3
Let just say that a user selected the row with the D_code1, then ListBox2 will fetch/show this:
– ListBox2–
B_code1 |D_code1 | RandomData1| RandomData1 | RandomData1 | RandomData1| RandomData1
B_code2 |D_code1 | RandomData2| RandomData2 | RandomData2 | RandomData2| RandomData2
B_code3 |D_code1 | RandomData3| RandomData3 | RandomData3 | RandomData3| RandomData3
B_code4 |D_code1 | RandomData4| RandomData4 | RandomData4 | RandomData4| RandomData4
B_code5 |D_code1 | RandomData5| RandomData5 | RandomData5 | RandomData5| RandomData5

Only the data with the same D_code was shown.
If selection changed, (D_code2 was selected) then all of the data with D_code2 will be shown and so on.

Do i need to make another query which will be the one responsible for fetching in ListBox2 ? or i can do it in Xojo only?

*will not be using plugins by the guys.
*i just need a guide since i’m new to xojo,

If I understand, he logic goes something like this:
When first seeing the window, listbox #1 loads, but listbox#2 is either empty, or fills information relating to the first highlighted row of listbox#1.

Either way, one needs to load listbox#2 whenever a row is highlighted in listBox1.
So - when the action is to select a row in listbox#1, need to clear all rows in listbox#2, then load listbox#

Something like an SQL statement in SQLite would be "select * from listbox#2table where listbox1_ID = D _code1)
to get a recordset containing those rows in the listbox#2 table that correspond to the ones you want.
Then load listbox#2 with the values you want.

Without knowing the exact database structure, hard to comment further.

Hope thatbhelps. I am still learning myself. Good luck.
Phil

That is exactly what i wanted to happen sir. However, im using mysql not SQLITE.

i just need these 2 tables from the dabatase sir.

[quote=466598:@Immanuel Cristobal]Tables/data that needs to be fetched from the database:

[b]*Listbox #1 → Table #1
D_code, randomdata1

*Listbox #2 → Table #2
B_code, D_code, randomdata1,randomdata2,randomdata3,randomdata4,random5[/b]

D_code from Listbox#1 is the same with Listbox2,
There is only one unique D_code in ListBox1 but there are duplicates in ListBox2[/quote]

it looks like i just need an additional sql statement, i was thinking of just doing it in Xojo.

[quote=466599:@Philip Cumpston]Hope thatbhelps. I am still learning myself. Good luck.
Phil[/quote]
Thank you sir. :smiley:

Hello Sir Philip,
I was now able to solve the task, thanks to you.

here is my code:

[code]If Me.ListIndex > -1 Then
SelectedDelivery = Me.Cell(Me.ListIndex, 0)
Var sql As String
sql = " SELECT * FROM table#2"
sql = sql + " WHERE Dcode = ‘" + SelectedDelivery + "’"
Var rs As RowSet
Try
rs = db.SelectSQL(sql)
Catch error as DatabaseException
MsgBox("DB Error: " + error.Message)
Return
End Try

If rs <> Nil Then
While Not rs.AfterLastRow
ListBoxProductsDeliveryBatch.AddRow(rs.Column(“Dcode”).StringValue, rs.Column(“Bcode”).StringValue, rs.Column(“randomdata1”).StringValue, rs.Column(“randomdata2”).StringValue, rs.Column(“randomdata3”).StringValue,rs.Column(“randomdata4”).StringValue,rs.Column(“randomdata5”).StringValue)
rs.MoveToNextRow
Wend
rs.Close
End If
End If[/code]

*SelectedDelivery is a property with DataType “String”.

First: Unsecure Programming, leads to SQL Injection with “… Dcode = '” + SelectedDelivery
Second: Your problem looks like simple SQL Joins in table2, isn’t it?

I am glad you got it working. I think Tomas has a simpler solution, but probably needs to explain to you how to do a join and present the results. But working this out for yourself will probably give you a greater understanding.
All th best
Phil

Sorry late reply.

it was just temporary sir, i am goin fix it.

Maybe sir, i am not really a backend guy, but i am now studying all about backend. I think you’re right sir. It looks like i just need to read all about sql.

[quote=466615:@Philip Cumpston]I am glad you got it working. I think Tomas has a simpler solution, but probably needs to explain to you how to do a join and present the results. But working this out for yourself will probably give you a greater understanding.
All th best
Phil[/quote]
yes sir, i would do it on my own. it’s my job anyway. thank you sir Tom & Phil. :slight_smile: