Assigning Items from a Mysql query to variables

Im trying to load the items which I receive from a Mysql query

This is a pic of what the query returns. It’s perfect cause it contains all the data, separated by a space that I need to place into variables but I don’t know how to do it

Please can anyone help


Thanks

The message on the phone… Now I am really confused

Would be nice to get an answer bfr it gets deleted?

Read :

Hey, I dont know. Im looking for answers myself :slight_smile:

1 Like

You have had many useful examples provided. You have asked this question on the App Inventor forum as well. Here are some blocks following the worded answer you received there. I have only written out 7 (seven) elements in the string, and set the outputs to labels, you can modify this example to save to tinydb tags (Would be better to save the list to a single tag, in my opinion). Apologies to Kodular users/mods for the AI2 blocks :wink:

This should resolve your issue.

Once you have your string converted to a list, you have all your outputs “in a variable”.

Example SQL string returned:

((8 22 2020-12-13 $first_name $last_name $E8_9 $E9_10))

image

As suggested on the App Inventor forum:

Use text replacement blocks to remove the parentheses (())
Convert what remains to a list using the text split by spaces block
Select each item from the list and assign to your chosen variables

In future, and as advised several times by me and others, if you are developing in a particular builder, please ask your questions in the builder that you are using, because the builders (App Inventor, Kodular, etc.) are becoming more different day by day and an answer given on for one builder may not apply or work on another.

You may also want to do some learning about lists:

General Tutorials

1 Like

Thanks for doing all that work. I really do appreciate it.

The above is the error message I get on my device.

I’m assuming it’s related to the the (expectation of a number) as per the blocks but yours returns data so I’ve obviously done something wrong.

Whats Wrong?

Thanks
t

geturl
The message shows that you have passed a URL. And see that you passed the variable that contains the URL. This is not the variable you must pass.


global get_SQL_DATA is wrong.

Change to alarm_list.
In its place, put that variable that received the response content there in your first post. (alarm_list)
This variable that contains your return.

csv

See your for each block.
1
SQLList
1
What you see ?
And message error, what you see in the error message?
range

So I changed it to [Item} and still it bombed
For Range : The end value is not a number???

Im loosing it1

What does the For Each block do ?

What are the 3 parameters of this block ?
1
SQLList
1

It goes tru the returned data one step at a time for the amt of data returned

This For each starts at 1 (number) to SQLLite (number?) Increment of (by) 1 (number).

See:
:point_down:t2: :point_down:t2: :point_down:t2: :point_down:t2: :point_down:t2:


:point_up:t2: :point_up:t2: :point_up:t2: :point_up:t2: :point_up:t2: :point_up:t2:

Yes, and that was why I changed it to [Item} but still no luck?

image

length2

Now it says - Select List item
: List index too large Select list item: Attempt to get item number 10 of a list of length 9???

but it wrote the returned values into the variables from the database which is fantastic

2 list with diferent sizes ?
twolist
The list he gave as an example was just … an example … you don’t need it …

but he was correct. I only need 9 items

$values = mysqli_query($dbc, "SELECT info_8_desc, (1)
info_9_desc, (2)
info_10_desc, (3)
info_11_desc, (4)
info_12_desc, (5)
info_13_desc, (6)
info_14_desc, (7)
info_15_desc, (8)
info_16_desc (9)
FROM info WHERE
node_id = ‘$Node_id’ AND info_date=’$Info_Date’ ");

Friend, if there is an error message saying you are trying to access the 10th element if there is only 9, please check your algorithm.

@TimAi2 has already given you the solution.

He gave you ready blocks.

He gave you links.