Hi All - I’m trying to display results of a SQL Query directly into the webpage that my app is running in. The front end app is super simple and is basically just some drop downs of choices to select. Once the user interacts with those drop downs, depending on the values they’ve selected, SQL runs on the back-end (external MySQL database in Azure) and those results are passed into a variable. So for example, here’s an example of what exists in the server code.
@anvil.server.callable
def get_all_items():
conn = connect()
with conn.cursor() as cur:
cur.execute(“SELECT * from items”)
return cur.fetchall()
I can easily call this in the client code and have it return results via the below client code.
def button_item_click(self, **event_args):
item_type_value = self.drop_down_1.selected_value
item_class_value = self.drop_down_2.selected_value
item_race_value = self.drop_down_3.selected_value
if item_type_value == "All":
print(anvil.server.call('get_all_items'))
The challenge is that while I can get the results displayed in a terminal window, I have no idea how to get this displayed on the webpage when a user interacts with it. What’s more is that I’d like them to be able to see the results, then if they go back and select different options from the drop downs, they could potentially have new SQL that runs and I’d like to display the updated results.
What I’m trying to do: Display results from a SQL Query directly in the webpage. Preferably in some type of table or whatever is easiest.
What I’ve tried and what’s not working: I don’t know where to start.
Code Sample:
Server Code: (See Above)
Clone link:
There is really no interaction working with this right now. Behind the scenes I’m getting the SQL to run, but you won’t see much within the app.
(Pantheon)
Thanks all!