我正在尝试使用json
文件将数据导入我的MySQL
表...但问题是我猜我无法在foreach中进行查询环。
是否可以在foreach
循环内进行查询?
编辑:我正在尝试多次运行此代码并且没有重复...但是b / c $r_check
不起作用,它会保留重复的条目..我在100k +可能的参赛作品时跑了12k
这是我的代码:
$latest = mysqli_query($con, "SELECT * FROM prod_designs ORDER BY pd_modified_at ASC LIMIT 1");
$row_lat = mysqli_fetch_array($latest);
$day = date("Y-m-d", strtotime($row_lat['pd_modified_at']));
$date = date_create($time);
date_add($date,date_interval_create_from_date_string("1 second"));
$new_time = date_format($date,"G:i:s");
$test_time = $day."T".$new_time."-05:00";
$str = file_get_contents('http://cdinternet.campdavid.com/Services/iPadDesignUtilities.asmx/GetDesignInfo?username=dew&password=Elv!s138&date='.$test_time.'&Structure=all&Max=12000');
$json = json_decode($str, true);
$count = count($json['designs']['images']);
$result = array();
foreach($json['designs']['images'] as $image) {
$name = $image['name'];
$url = $image['url'];
$created_at = $image['created-at'];
$modified_at = $image['modified-at'];
$img_mod_at = $image['image-modified-at'];
$release_date = $image['release-date'];
$desg_num = $image['design-number'];
$desc = $image['description'];
$top_selling = $image['top-selling'];
$add_price = $image['additional-price'];
$level_id = $image['level_id'];
$place = $image['placement'];
$designer = $image['designer'];
$new_mod = $image['new-or-modified'];
$style = $image['style'];
$recco_for_style = $image['recommended-for-style'];
$cust = $image['customer'];
$protected = $image['protected'];
$isdeleted = $image['isdeleted'];
$isecda = $image['isecda'];
$parent = $image['parent'];
$notes = $image['notes'];
$year = $image['year'];
$div = $image['division'];
$gender = $image['gender'];
$location = $image['location'];
$price_code = $image['price-code'];
$keywords = $image['keywords'];
$tags = $image['tags'];
$category = $image['category'];
$embellishment = $image['embellishment'];
$trend = $image['trend'];
$check = mysqli_query($con, "SELECT pd_name FROM prod_designs WHERE pd_name = '$name'");
$r_check = mysqli_fetch_array($check);
if($r_check['pd_name'] != $name) {
echo "Nope";
} else {
$insert = mysqli_query($con, "INSERT INTO prod_designs (pd_name, pd_url, pd_created_at, pd_modified_at, pd_img_mod_at, pd_release_date, pd_desg_num, pd_desc, pd_top_selling, pd_gender, pd_price_code, pd_add_price, pd_embell, pd_level_id, pd_place, pd_designer, pd_year, pd_new_mod, pd_location, pd_style, pd_trend, pd_category, pd_recco_for_style, pd_div, pd_cust, pd_protected, pd_isdeleted, pd_isecda, pd_parent, pd_keywords, pd_tags, pd_notes ) VALUES ('$name', '$url', '$created_at', '$modified_at', '$img_mod_at', '$release_date', '$desg_num', '$desc', '$top_selling', '$gender', '$price_code', '$add_price', '$embellishment', '$level_id', '$place', '$designer', '$year', '$new_mod', '$location', '$style', '$trend', '$category', '$recco_for_style', '$div', '$cust', '$protected', '$isdeleted', '$isecda', '$parent', '$keywords', '$tags', '$notes')");
if($insert) {
echo "INSERTED<br>";
}
}
}