Android Question compare table record on mysql?

ilan

Expert
Licensed User
Longtime User
hi

i have a sqlite db that has many columns but 2 important columns.

id & ver

now i have a online db where i fill all new data to it.
the app should send an array from all records with key id and value ver
and via php compare with the online db if for the specific id the ver is newer then return it via array

so i dont want to return a single record i want to return all records with a newer version.

i just dont find it efficient to download the whole table and make the comparison in the b4x app. instead i would like to make it online. (php)

so the app should create a arra with key & value (i was thinking maybe json string) and then upload to the php server and make the check there. the problem is i dont find the answer how to get from the json array the json object by key.

any suggestions?
 
Last edited:

ilan

Expert
Licensed User
Longtime User
ok figured it out:

b4x:

B4X:
    Dim jsonstr As String = $"[{"audioid":"w0R2Ppk5","ver":"0"},{"audioid":"ne47IX5A","ver":"1"}]"$
    Wait For (Main.mysqlClass.downLoadAudio(jsonstr)) Complete (audioMap As Map)
    Log(audioMap.Size)


PHP:


PHP:
Case "getallaudio":
        $json = file_get_contents('php://input');       
        $data = json_decode($json);
        $table = $data->mytable;
        $jsonstr = $data->jsonstr;
        $arr = json_decode($jsonstr);
        $rows = array();
        
        $q = mysqli_query($con, "SELECT * FROM $table");
        while($r = mysqli_fetch_assoc($q))
        {
            $audioid_value = $r['audioid'];
            $ver_value = $r['ver'];
            $found = false;
            
            foreach($arr As $item) { //foreach element in $arr
                $audioid = $item->audioid;
                $ver = $item->ver;
                
                if($audioid_value == $audioid){
                    $found = true;
                    if($ver_value > $ver){
                        $rows[] = $r;
                    }
                    break;
                }
            }
            
            if ($found == false){
                $rows[] = $r;
            }           
        }           
        
        print json_encode($rows);
        mysqli_free_result($q);
        break;

now all i need to do is the create dynamically the json string what is quite simple.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…