Example #1
0
function insertToDatabase($xml)
{
    //kopplar in till database
    $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    if (!$mysqli) {
        echo "Det här gick ju inte så bra!";
    }
    //Tömmer tabellen så att den blir nollställd
    $mysqli->query("truncate apk_data");
    //sätter upp prepered
    $stmt = $mysqli->prepare("INSERT INTO apk_data (id,item_id,name,name2, department,volym,price, alcohol_by_volym, apk, status) VALUES (?,?,?,?,?,?,?,?,?,?)");
    $stmt->bind_param("iisssdddds", $id, $artikelid, $name, $name2, $department, $volym, $price, $alcoholByVolym, $apk, $status);
    $char = ",";
    $csvFile = "";
    //Loppar igenom alla artiklar
    foreach ($xml->artikel as $attribute) {
        $id = $attribute->nr;
        $artikelid = $attribute->Artikelid;
        $name = utf8_decode(deleteComma($attribute->Namn));
        $name2 = utf8_decode(deleteComma($attribute->Namn2));
        $department = utf8_decode(getDep($attribute->Varugrupp));
        $price = floatval($attribute->Pant) + floatval($attribute->Prisinklmoms);
        $volym = floatval($attribute->Volymiml);
        $alcoholByVolym = calcAlc($attribute->Alkoholhalt);
        $apk = calcAPK($price, $volym, $alcoholByVolym);
        $status = $attribute->Sortiment;
        //Kör satsen
        $stmt->execute();
    }
}
Example #2
0
function insertToDatabase($complatePageArray)
{
    //kopplar in till database
    $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    if (!$mysqli) {
        echo "Det här gick ju inte så bra!";
    }
    //sätter upp prepered
    $stmt = $mysqli->prepare("INSERT INTO apk_silja (id,item_id,name,name2, department,volym,price, alcohol_by_volym, apk, status) VALUES (?,?,?,?,?,?,?,?,?,?)");
    if (!$stmt) {
        echo "Det gick inte så bra att göra prepare";
    }
    $stmt->bind_param("iisssdddds", $id, $artikelid, $name, $name2, $department, $volym, $price, $alcoholByVolym, $apk, $status);
    //Loppar igenom alla artiklar
    foreach ($complatePageArray as $pageArray) {
        foreach ($pageArray as $value) {
            $id = $value->id;
            $artikelid = $value->siljaOscarCode;
            if (isset($value->brandName)) {
                $name = utf8_decode($value->brandName);
            } else {
                $name = "";
            }
            if (isset($value->itemCatalogName)) {
                $name2 = utf8_decode($value->itemCatalogName);
            } else {
                $name2 = "";
            }
            if (isset($value->productSpecificationTranslated)) {
                $department = utf8_decode($value->productSpecificationTranslated);
            } else {
                echo $value->brandName . "\n";
            }
            //$department = $value->productSpecificationTranslated;
            $price = $value->lowestPrice;
            if (strpos($value->size, '*')) {
                $volym = getVolym($value->size);
            } else {
                $volym = $value->size;
            }
            $alcoholByVolym = procentToDecimal($value->alc);
            $apk = calcAPK($price, $volym, $alcoholByVolym);
            if (isset($value->campaignType)) {
                $status = $value->campaignType;
            } else {
                $status = "";
            }
            $stmt->execute();
        }
    }
}