MySQL query to ListView

Hello everyone,
In this guide I am going to practically show you how to set list in ListView from a returned value of a custom MySQL query.

Citation and Credit goes to:
@Taifun - Pura Vida Apps
@Hossein - Daily Challenge 29
@Rogerio_Rios - for pointing out the mistakes.

STEP 1: Server Setup

  1. Put the PHP code on your web server. mysql.TXT (4.4 KB) (Please change the extension from .txt to .php before uploading)
  2. Set the SQLKEY in your app and in the PHP code, they must match for this code to work. Don’t use special characters.
  3. Setup your database connection information in the PHP script.

STEP 2: Designing the App Interface
1 Button and 1 ListView. You can use any ListView you want, I am using the default one.


1 Web component as well.
Components

STEP 3: Preparing URL and Query to execute in the Script


This will prepare the query to execute in the php script on the provided url.
Sample Table
This is the table in our database.

STEP 4: Executing Query and getting values
Run

each row of a table contains information from an “item” of the class (table).
Then the return of your Select, 4 lines were returned. The other 3 lines contain information for each item in the list. Like:
line 1, item 1 - name’s military
line 1, item 2 - rank’s military
line 1, item 3 - force’s military
next line. …
next line …

So when we receive the response we will just Split and replace the \n and , likewise:
blocks (7)

Final look:


Final Blocks:

That’s it! You’ve got your list setup in a ListView from a custom MySQL query.
AIA File: MySQL (1).aia (6.5 KB)

Suggestions and corrections are welcomed. My next guide will be on how to make a recyclerview with MySQL Query. Thanks for reading.

6 Likes

Inversed Matrix ?

Friend, each row of a table contains information from an “item” of the class (table).
Then the return of your Select, 4 lines were returned (the first one informs the field names - this information can be removed in the php script itself or ignoring it in a for each loop).
The other 3 lines contain information for each “military”.
line 1, item 1 - name’s military
line 1, item 2 - rank’s military
line 1, item 3 - force’s military
next line. …
next line …

This is the correct way.

image

I think I didn’t understand …

your example could be simplified…
there is no need to change columns and rows in this case… i.e. no need for step 5 and step 6…
see this screenshot


Taifun

4 Likes

That’s what I said…

1 Like

That is so kind of you (@Taifun and @Rogerio_Rios ) for explaining that to me practically, I got my mistake. Will update the post asap. :grinning:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.