Results 1 to 1 of 1

Thread: Cuted records from API to Database

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Cuted records from API in Database

    Hi! I have my own web app, but with one small problem. I have a script to store data in DB, but it's inserts only random records, not all. Any ideas?

    My code:

    PHP Code:
    <?php  foreach ($members as $member) { // odbieramy dane z formularza $id = $member["clanRank"];$liga = $member["league"]["name"];$lvl = $member["expLevel"];$tag = $member["tag"];$nick = $member["name"]; $ranga = $member["role"];$donated = $member["donations"];$received = $member["donationsReceived"];$puchary = $member["trophies"];$datan = date("Y-m-d");$czas = date("H:i");$ratio = $donated - $received;$sa = date_default_timezone_set('Europe/Warsaw');
    if($id and $liga and $lvl and $tag and $nick and $ranga and $donated and $received and $puchary) {          // łączymy się z bazą danych     $connection = @mysql_connect($servername, $username, $password)     or die('Brak połączenia z serwerem MySQL');     $db = @mysql_select_db($dbname, $connection)     or die('Nie mogę połączyć się z bazą danych');          $ins = @mysql_query("REPLACE INTO klan SET miejsce='$id', liga='$liga', poziom='$lvl', tag='$tag', nick='$nick',     ranga='$ranga', donated='$donated', received='$received', roznica='$ratio', puchary='$puchary', data='$datan', aktualizacja='$czas'");           }     }          if($ins) echo "Zaktualizowano bazę danych<br>";     else echo "Błąd nie udało się zaktualizować<br>";         ?>
    API connection code:

    PHP Code:
     <?php $clantag "#28LJOYOLQ";
    $clanurl "https://api.clashofclans.com/v1/clans/" urlencode($clantag);
    $ch curl_init($clanurl);
    $headr = array();$headr[] = "Accept: application/json";$headr[] = "Authorization: Bearer ".$token;
    curl_setopt($chCURLOPT_HTTPHEADER$headr);curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);curl_setopt($chCURLOPT_RETURNTRANSFER1); 
    $res curl_exec($ch);$data json_decode($restrue);curl_close($ch);
    if (isset(
    $data["reason"])) {  $errormsg true;}
    $members $data["memberList"];
    ?>

    PLS help
    Last edited by 69ZBOCZUCH69; May 3rd, 2019 at 10:31 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •