[ Ïîèñê ] - [ Ïîëüçîâàòåëè ] - [ Êàëåíäàðü ]
Ïîëíàÿ Âåðñèÿ: Ïî÷åìó öèêë çàïóñêàåòñÿ òîëüêî îäèí ðàç ?
Sice
Äîáðûé äåíü, äðóçüÿ.

Åñòü êîä:
    if(mysql_num_rows($query_user) > 0){ // Åñëè Èãðîê ñóùåñòâóåò... òî.. äåëàåì çàïðîñ è âûâîäèì ïîñëåäíèå ìàò÷è
        $select_matches = "SELECT * FROM lastm WHERE steam_id64=$_GET[steam_id]";
        $query_matches = mysql_query($select_matches);
    
            if(mysql_num_rows($query_matches) == 0){ // 1. Èãðîê çàø¸ë â ïåðâûé ðàç..
                    $url = file_get_contents("https://site.com/?account_id=".$_GET['steam_id']."&key=".$steamauth['apikey'].""); 
                    $match = json_decode($url, true);
                    $result_json = $match['result'];
                        foreach ($result_json['matches'] as $match) { // Äîáàâëÿåì ìàò÷è â ÁÄ...

                        $sql = mysql_query("INSERT INTO lastm (match_id, steam_id64, start_time, lobby_type) VALUES ('$match[match_id]','$_GET[steam_id]','$match[start_time]','$match[lobby_type]')");
                                
$url2 = file_get_contents("https://site.com/?match_id=".$match[match_id]."&key=".$steamauth['apikey'].""); 
                                   $match2 = json_decode($url2, true);
                                  $result_json2 = $match2['result'];    
                                    
$sql = mysql_query("INSERT INTO matches (radiant_win, duration, start_time, match_id, match_seq_num, tower_status_ radiant, tower_status_dire, barracks_status_radiant, barracks_status_dire, cluster, first_blood_time,  lobby_type, human_players, leagueid, positive_votes, negative_votes, game_mode) VALUES ('$result_json2[radiant_win]','$result_json2[duration]','$result_json2[start_time]','$result_json2[match_id]','$result_json2[match_seq_num]','$result_json2[tower_status_radiant]','$result_json2[tower_status_dire]','$result_json2[barracks_status_radiant]','$result_json2[barracks_status_dire]','$result_json2[cluster]','$result_json2[first_blood_time]','$result_json2[lobby_type]','$result_json2[human_players]','$result_json2[leagueid]','$result_json2[positive_votes]','$result_json2[negative_votes]','$result_json2[game_mode]')");
                                            
                                            foreach ($result_json2['players'] as $players) {
                                             $sql = mysql_query("INSERT INTO account (match_id, account_id, player_slot, hero_id, item_0, item_1, item_2, item_3, item_4, item_5, kills, deaths, assists, leaver_status, gold, last_hits, den ies, gold_per_min, xp_per_min, gold_spent, hero_damage, tower_damage, hero_healing, level) VALUES (' $result_json2[match_id]','$players[account_id]','$players[player_slot]','$players[hero_id]','$players[item_0]','$players[item_1]','$players[item_2]','$players[item_3]','$players[item_4]','$players[item_5]','$players[kills]','$players[deaths]','$players[assists]','$players[leaver_status]','$players[gold]','$players[last_hits]','$players[denies]','$players[gold_per_min]','$players[xp_per_min]','$players[gold_spent]','$players[hero_damage]','$players[tower_damage]','$players[hero_healing]','$players[level]')");
                                        }
                                        
                                    }

            }
    }

Äàííûé êîä ïàðñèò äàííûå ñ ñàéòà, çàíîñèò ñíà÷àëà ñïèñîê ìàò÷åé â ÁÄ, ïîòîì äåòàëè ìàò÷à. Âñ¸ ðàáîòàåò ïðàâèëüíî, íî ïî÷åìó-òî ïîñëåäíèé öèêë:

 foreach ($result_json2['players'] as $players) {
                                             $sql = mysql_query("INSERT INTO account (match_id, account_id, player_slot, hero_id, item_0, item_1, item_2, item_3, item_4, item_5, kills, deaths, assists, leaver_status, gold, last_hits, den ies, gold_per_min, xp_per_min, gold_spent, hero_damage, tower_damage, hero_healing, level) VALUES (' $result_json2[match_id]','$players[account_id]','$players[player_slot]','$players[hero_id]','$players[item_0]','$players[item_1]','$players[item_2]','$players[item_3]','$players[item_4]','$players[item_5]','$players[kills]','$players[deaths]','$players[assists]','$players[leaver_status]','$players[gold]','$players[last_hits]','$players[denies]','$players[gold_per_min]','$players[xp_per_min]','$players[gold_spent]','$players[hero_damage]','$players[tower_damage]','$players[hero_healing]','$players[level]')");  
                                      }


Ñðàáàòûâàåò îäèí ðàç, è çàíîñèò äàííûå òîëüêî ñ ïåðâîé ÿ÷åéêîé äàííûõ ìàññèâà $players.
Ñàì ìàññèâ $players â JSON âûãëÿäèò âîò òàê:

{
"result": {
"players": [
{
"account_id": 2067850,
"player_slot": 0,
"hero_id": 99,
"item_0": 242,
"item_1": 127,
"item_2": 34,
"item_3": 114,
"item_4": 63,
"item_5": 0,
"kills": 12,
"deaths": 1,
"assists": 20,
"leaver_status": 0,
"gold": 2268,
"last_hits": 104,
"denies": 15,
"gold_per_min": 588,
"xp_per_min": 632,
"gold_spent": 13375,
"hero_damage": 15128,
"tower_damage": 1715,
"hero_healing": 0,
"level": 17,
{
"ability": 5002,
"time": 1977,
"level": 17
}
]

},
{
"account_id": 4294967295,
"player_slot": 1,
"hero_id": 4,
"item_0": 0,
"item_1": 71,
"item_2": 11,
"item_3": 63,
"item_4": 137,
"item_5": 154,
"kills": 15,
"deaths": 2,
"assists": 21,
"leaver_status": 0,
"gold": 2715,
"last_hits": 93,
"denies": 12,
"gold_per_min": 595,
"xp_per_min": 450,
"gold_spent": 12325,
"hero_damage": 16657,
"tower_damage": 3510,
"hero_healing": 1110,
"level": 14,
// È ÒÀÊ ÄÀËÅÅ..., ÒÀÊÎÃÎ ÆÅ ÐÎÄÀ ÄÀÍÍÛÅ...

 èòîãå öèêë foreach ïî÷åìó-òî çàíîñèò òîëüêî ïåðâóþ ÿ÷åéêó â ÁÄ, îñòàëüíûå ïðîõîäèò è èä¸ò ê ñëåäóþùåìó $match_id (ìàò÷ó). Ïî÷åìó òàê ? Çàðàíåå ñïàñèáî !
Áûñòðûé îòâåò:

 Ãðàôè÷åñêèå ñìàéëèêè |  Ïîêàçûâàòü ïîäïèñü
Çäåñü ðàñïîëîæåíà ïîëíàÿ âåðñèÿ ýòîé ñòðàíèöû.
Invision Power Board © 2001-2024 Invision Power Services, Inc.