Page 1 of 1

Extracting data by means of an API

Posted: 2021-10-25 18:12
by RonP
Hi,
I'm looking for a way to extract data from a table by means of an API.
I would like to just access the zip codes, "indicator codes" (like "Member/Non Member") from the "Members Table".
With that data I would Plot a map.

What I do now is extracting this fields as .csv and then go to a plot application.
So if I could skip the extracting step ..... that would be great.
Is this possible or does this already exists?

Ron

Re: Extracting data by means of an API

Posted: 2021-10-25 20:33
by pbottcher
Hi Ron,

actually you can write a small php script that extracts your data and either save it as a csv file, or just echo it out.

Otherwise the is the API https://github.com/rafinhacarneiro/appgini-api that you may try.

Re: Extracting data by means of an API

Posted: 2021-10-26 16:25
by Alisson
If your plot application can import json data instead of csv, this code can help you.

Create a file called export.php inside your hooks folder

Code: Select all

<?php
    include("../lib.php");

    $query = sql("SELECT * FROM members", $eo);
    
    $json_array = array();  
    while($row = mysqli_fetch_assoc($query))  
    {  
        $data[] = $row;
    }  
    echo(json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK));

?> 
By accessing the export.php it will generate the data you need in json format

Otherwise you can try this code that will output a csv data:

Code: Select all

<?php
    include("../lib.php");

    $query = sql("SELECT * FROM members", $eo);
    
    $json_array = array();  
    while($row = mysqli_fetch_assoc($query))  
    {  
        $data[] = $row;
    }  
    
     $jsondata = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);

    $jsonans = json_decode($jsondata, true);
    $file_pointer = fopen('php://output', 'w');
    foreach($jsonans as $i){
        fputcsv($file_pointer, $i);
    }
    fclose($file_pointer);

?> 
PS. Change the query to reflect your need.

Re: Extracting data by means of an API

Posted: 2021-10-26 17:08
by RonP
Hi PBöttcher and Alisson,
Thans you both to pointing to some solutions.
I’ll have werk to do :D
Ron

Re: Extracting data by means of an API

Posted: 2021-12-29 10:39
by RonP
Two months later ;)
Well, I've found someone within my volunteers club, he made a nice, secured, interactive plot for me.
Thank you for pointing to the solution.
A screen crab from the result :)

Ron