Android Question php>csv>map can i save a step?

aidymp

Well-Known Member
Licensed User
Longtime User
Hi I call a php, it returns a csv file, I then save this file, and open it as a csv and add the data to a map.

Seems a little long winded, to me especially as I do this around 10 times on the start of an app.

is there a way to instead download and add it to a map? without all the saving and loading, i only use this method because I saw the loadcsv command.

Thanks

Aidy
 

DonManfred

Expert
Licensed User
Longtime User
Probably you can do all the work with calling the php one time and returns a list of all maps needed in one result-json....
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
Thanks Guys, I will take a look into this. any tutorials, or examples would still be welcome ;)

Thanks

Aidy
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
1. Upload your php-file you are using
2. Upload a db-dump with at least some dummy-data (the scheme is important)

Maybe the solution is easy

Hi Manfred thanks for the offer, I am trying to work it out myself or I will never learn! lol (but please stick around ;) )

So far I found a tutorial for PHP exports the table as JSON (that was much easier than expected!!) link here
I found the JSON Tree Example, that amazingly made part of the code for me! (WOW!) link here
I now call the PHP, and can read the JSON into my program! (This is much better than calling the 10+ PHP's and then saving the file, opening it as a csv adding it to a map blah, blah...) link here (written by someone cool!)

***** EDITED AS IT WORKS!!!

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
Dim Updated As String = colroot.Get("Updated")
Dim Authorized As String = colroot.Get("Authorized")
Dim Rate As String = colroot.Get("Rate")
Dim BuildDescription As String = colroot.Get("BuildDescription")
....

'>> HERE I ADD EACH OF MY ITEMS TO A MAP!

Next

Thank you so much! I was hoping to save the step of saving and loading the file > csv
as well as that, I have now saved using 10 + php files, saving and opening the csv adding to a map, in 10+ subs! this is done in about 20 lines of code, as opposed to the several hundred I was using prior! maybe the post should have said can I save about 50 steps! lol

I really have to say Im really impressed by B4X and its amazing community.

Thanks again!

Aidy
 
Last edited:
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
This is related, but not directly to B4X I have this working (amazingly all by myself) and its fixed a few bugs i had, (eg, some data in the table was returned as null or just crashed the app, (i think the data contained puctuation)) however, its working fine now!

Now the PHP, is my problem when I had 10+ PHP files (one for each map) I set the mainname to return in date order (latest first) so in my app the newest files where shown first! however this is no longer the case (i think due to the simplicity of the PHP)

Also my last updated, was a (google found) PHP that returned results like 5 mins ago, 1 week ago, but now its just showing the timestamp (as expected)

Obviously this is the B4X forum, NOT the PHP forum, but im wondering if anyone could give me hints on how I can get the result im looking for?? if not just ignore me!
;)

<?php //open connection to mysql db $connection = mysqli_connect("localhost","XXXXXXXXX","XXXXXXXXXXXX","XXXXXXXXXXX") or die("Error " . mysqli_error($connection));

//fetch table rows from mysql db
$sql = "select * from BuildData";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));

//create an array
$emparray = array();
while($row =mysqli_fetch_assoc($result))
{
$emparray[] = $row;
}
echo json_encode($emparray);

//close the db connection
mysqli_close($connection);

So the question how would i sort the output by a field called Updated?

An B) the updated field returns a timestamp, But I have php to make it fuzzy like (ten minutes ago, 1 Week ago)

with question b)

I could still use the PHP, but dont want to as thats the whole point of the main post!
maybe i could integrate that php into this to get the desired result?
maybe there is some code that i can change the timestamp to fuzzy in B4X??

Thanks!

Aidy
 
Upvote 0
Top