Skocz do zawartości
Zaloguj się, aby obserwować  
SaVaGe123

Pobranie danych z tablicy do pętli.

Polecane posty

Witam,

otóż posiadam taką tablicę:

Array ( [ConnectionsCurrent] => 88 [ConnectionsTotal] => 65979 [ConnectionsTotalAccepted] => 65979 [ConnectionsTotalRejected] => 0 [MessagesInBytesRate] => 809367.0 [MessagesOutBytesRate] => 1.0944831E7 [VHost] => Array ( [Name] => _defaultVHost_ [TimeRunning] => 157378.997 [ConnectionsLimit] => 0 [ConnectionsCurrent] => 88 [ConnectionsTotal] => 65979 [ConnectionsTotalAccepted] => 65979 [ConnectionsTotalRejected] => 0 [MessagesInBytesRate] => 809367.0 [MessagesOutBytesRate] => 1.0944831E7 [Application] => Array ( [Name] => live [status] => loaded [TimeRunning] => 51401.687 [ConnectionsCurrent] => 88 [ConnectionsTotal] => 26100 [ConnectionsTotalAccepted] => 26100 [ConnectionsTotalRejected] => 0 [MessagesInBytesRate] => 809367.0 [MessagesOutBytesRate] => 1.0944831E7 [ApplicationInstance] => Array ( [Name] => _definst_ [TimeRunning] => 51401.684 [ConnectionsCurrent] => 88 [ConnectionsTotal] => 26099 [ConnectionsTotalAccepted] => 26099 [ConnectionsTotalRejected] => 0 [MessagesInBytesRate] => 809367.0 [MessagesOutBytesRate] => 1.0940456E7 [stream] => Array ( [0] => Array ( [Name] => hbo-hd [sessionsFlash] => 0 [sessionsCupertino] => 0 [sessionsSanJose] => 0 [sessionsSmooth] => 0 [sessionsRTSP] => 0 [sessionsTotal] => 0 ) [1] => Array ( [Name] => polsat-sport [sessionsFlash] => 20 [sessionsCupertino] => 0 [sessionsSanJose] => 0 [sessionsSmooth] => 0 [sessionsRTSP] => 0 [sessionsTotal] => 20 ) [2] => Array ( [Name] => polsat-hd [sessionsFlash] => 4 [sessionsCupertino] => 0 [sessionsSanJose] => 0 [sessionsSmooth] => 0 [sessionsRTSP] => 0 [sessionsTotal] => 4 ) [3] => Array ( [Name] => kiepscy [sessionsFlash] => 3 [sessionsCupertino] => 0 [sessionsSanJose] => 0 [sessionsSmooth] => 0 [sessionsRTSP] => 0 [sessionsTotal] => 3 ) [4] => Array ( [Name] => azap1 [sessionsFlash] => 31 [sessionsCupertino] => 0 [sessionsSanJose] => 0 [sessionsSmooth] => 0 [sessionsRTSP] => 0 [sessionsTotal] => 31 ) [5] => Array ( [Name] => maxio-test2 [sessionsFlash] => 5 [sessionsCupertino] => 0 [sessionsSanJose] => 0 [sessionsSmooth] => 0 [sessionsRTSP] => 0 [sessionsTotal] => 5 ) [6] => Array ( [Name] => 4fun [sessionsFlash] => 0 [sessionsCupertino] => 0 [sessionsSanJose] => 0 [sessionsSmooth] => 0 [sessionsRTSP] => 0 [sessionsTotal] => 0 ) [7] => Array ( [Name] => maxio-csport [sessionsFlash] => 9 [sessionsCupertino] => 0 [sessionsSanJose] => 0 [sessionsSmooth] => 0 [sessionsRTSP] => 0 [sessionsTotal] => 9 ) ) ) ) ) )

 

I zastanawiam się jak w php zrobić pętlę o takiej zasadzie:

while() {
mysql_query('UPDATE `channels` SET `online`='$a['SessionsTotal'] WHERE `name`=$a['4fun']");
}

 

Problemem jest ustawianie pętli oraz te tablice w tablicy.

 

Proszę o pomoc.

Pozdrawiam.

Udostępnij ten post


Link to postu
Udostępnij na innych stronach

Ciężko wywnioskować co chcesz osiągnąć.

 

btw. rada, jak używasz print_r(); to albo kopiuj ze źródła strony, albo używaj tak:

echo '<pre>' . print_r($array, true) . '</pre>';
Edytowano przez xorg (zobacz historię edycji)

Udostępnij ten post


Link to postu
Udostępnij na innych stronach

Może inaczej :)

Mam o taki XML:

<WowzaMediaServer>
<ConnectionsCurrent>133</ConnectionsCurrent>
<ConnectionsTotal>69753</ConnectionsTotal>
<ConnectionsTotalAccepted>69753</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>833361.0</MessagesInBytesRate>
<MessagesOutBytesRate>1.2121459E7</MessagesOutBytesRate>
<VHost>
<Name>_defaultVHost_</Name>
<TimeRunning>162907.081</TimeRunning>
<ConnectionsLimit>0</ConnectionsLimit>
<ConnectionsCurrent>133</ConnectionsCurrent>
<ConnectionsTotal>69753</ConnectionsTotal>
<ConnectionsTotalAccepted>69753</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>833361.0</MessagesInBytesRate>
<MessagesOutBytesRate>1.2121459E7</MessagesOutBytesRate>
<Application>
<Name>live</Name>
<Status>loaded</Status>
<TimeRunning>56929.771</TimeRunning>
<ConnectionsCurrent>133</ConnectionsCurrent>
<ConnectionsTotal>29874</ConnectionsTotal>
<ConnectionsTotalAccepted>29874</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>833361.0</MessagesInBytesRate>
<MessagesOutBytesRate>1.2121459E7</MessagesOutBytesRate>
<ApplicationInstance>
<Name>_definst_</Name>
<TimeRunning>56929.768</TimeRunning>
<ConnectionsCurrent>133</ConnectionsCurrent>
<ConnectionsTotal>29873</ConnectionsTotal>
<ConnectionsTotalAccepted>29873</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>832610.0</MessagesInBytesRate>
<MessagesOutBytesRate>1.2111517E7</MessagesOutBytesRate>
<Stream>
<Name>hbo-hd</Name>
<SessionsFlash>4</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>4</SessionsTotal>
</Stream>
<Stream>
<Name>polsat-sport</Name>
<SessionsFlash>35</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>35</SessionsTotal>
</Stream>
<Stream>
<Name>polsat-hd</Name>
<SessionsFlash>9</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>9</SessionsTotal>
</Stream>
<Stream>
<Name>kiepscy</Name>
<SessionsFlash>0</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>0</SessionsTotal>
</Stream>
<Stream>
<Name>azap1</Name>
<SessionsFlash>34</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>34</SessionsTotal>
</Stream>
<Stream>
<Name>ockotv</Name>
<SessionsFlash>0</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>0</SessionsTotal>
</Stream>
<Stream>
<Name>maxio-test2</Name>
<SessionsFlash>9</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>9</SessionsTotal>
</Stream>
<Stream>
<Name>4fun</Name>
<SessionsFlash>1</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>1</SessionsTotal>
</Stream>
<Stream>
<Name>maxio-csport</Name>
<SessionsFlash>16</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>16</SessionsTotal>
</Stream>
<Stream>
<Name>nickelodeon-hd</Name>
<SessionsFlash>5</SessionsFlash>
<SessionsCupertino>0</SessionsCupertino>
<SessionsSanJose>0</SessionsSanJose>
<SessionsSmooth>0</SessionsSmooth>
<SessionsRTSP>0</SessionsRTSP>
<SessionsTotal>5</SessionsTotal>
</Stream>
</ApplicationInstance>
</Application>
</VHost>
</WowzaMediaServer>

 

Z pola <Stream> chce pobrać <Name> oraz <SessionsTotal> i wrzucić je do bazy. Pobieram XML, przetwarzam go na tablicę tą co Ci podałem, dalej nie mam pojęcia co robić :)

 

[EDIT]

 

btw. rada, jak używasz print_r(); to albo kopiuj ze źródła strony, albo używaj tak:

echo '<pre>' . print_r($array, true) . '</pre>';

Dzięki za radę :) Widzę teraz jak pobrać wartości. Kod wygląda tak:

Array
(
    [ConnectionsCurrent] => 133
    [ConnectionsTotal] => 69960
    [ConnectionsTotalAccepted] => 69960
    [ConnectionsTotalRejected] => 0
    [MessagesInBytesRate] => 911021.0
    [MessagesOutBytesRate] => 1.3815473E7
    [VHost] => Array
        (
            [Name] => _defaultVHost_
            [TimeRunning] => 163181.351
            [ConnectionsLimit] => 0
            [ConnectionsCurrent] => 133
            [ConnectionsTotal] => 69960
            [ConnectionsTotalAccepted] => 69960
            [ConnectionsTotalRejected] => 0
            [MessagesInBytesRate] => 911021.0
            [MessagesOutBytesRate] => 1.3815473E7
            [Application] => Array
                (
                    [Name] => live
                    [status] => loaded
                    [TimeRunning] => 57204.041
                    [ConnectionsCurrent] => 133
                    [ConnectionsTotal] => 30081
                    [ConnectionsTotalAccepted] => 30081
                    [ConnectionsTotalRejected] => 0
                    [MessagesInBytesRate] => 911021.0
                    [MessagesOutBytesRate] => 1.3815473E7
                    [ApplicationInstance] => Array
                        (
                            [Name] => _definst_
                            [TimeRunning] => 57204.038
                            [ConnectionsCurrent] => 133
                            [ConnectionsTotal] => 30080
                            [ConnectionsTotalAccepted] => 30080
                            [ConnectionsTotalRejected] => 0
                            [MessagesInBytesRate] => 911021.0
                            [MessagesOutBytesRate] => 1.3815473E7
                            [stream] => Array
                                (
                                    [0] => Array
                                        (
                                            [Name] => hbo-hd
                                            [sessionsFlash] => 6
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 6
                                        )

                                    [1] => Array
                                        (
                                            [Name] => polsat-sport
                                            [sessionsFlash] => 34
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 34
                                        )

                                    [2] => Array
                                        (
                                            [Name] => polsat-hd
                                            [sessionsFlash] => 8
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 8
                                        )

                                    [3] => Array
                                        (
                                            [Name] => kiepscy
                                            [sessionsFlash] => 3
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 3
                                        )

                                    [4] => Array
                                        (
                                            [Name] => azap1
                                            [sessionsFlash] => 33
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 33
                                        )

                                    [5] => Array
                                        (
                                            [Name] => ockotv
                                            [sessionsFlash] => 0
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 0
                                        )

                                    [6] => Array
                                        (
                                            [Name] => maxio-test2
                                            [sessionsFlash] => 10
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 10
                                        )

                                    [7] => Array
                                        (
                                            [Name] => 4fun
                                            [sessionsFlash] => 0
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 0
                                        )

                                    [8] => Array
                                        (
                                            [Name] => maxio-csport
                                            [sessionsFlash] => 18
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 18
                                        )

                                    [9] => Array
                                        (
                                            [Name] => nickelodeon-hd
                                            [sessionsFlash] => 1
                                            [sessionsCupertino] => 0
                                            [sessionsSanJose] => 0
                                            [sessionsSmooth] => 0
                                            [sessionsRTSP] => 0
                                            [sessionsTotal] => 1
                                        )

                                )

                        )

                )

        )

)

 

Kod:


echo $a['VHost']['Application']['ApplicationInstance']['Stream']['0']['Name']; 

 

Wywołuje wartość.

Lecz nadal zastanawiam się nad ustawieniami pętli.

Edytowano przez SaVaGe123 (zobacz historię edycji)

Udostępnij ten post


Link to postu
Udostępnij na innych stronach

Chodzi mi tutaj o same ustawienia w pętli tak aby pobierała ona Name z ID od

$a['VHost']['Application']['ApplicationInstance']['Stream']['0']['Name']

 

Do końca listy. Czyli obecnie do:

$a['VHost']['Application']['ApplicationInstance']['Stream']['9']['Name']

 

 

Udostępnij ten post


Link to postu
Udostępnij na innych stronach

Proszę, to Cię powinno zadowolić:

 

foreach($a['VHost']['Application']['ApplicationInstance']['Stream'] AS $key => $value) {
 
      echo $value['Name'] . '<br />';
}
:)

Udostępnij ten post


Link to postu
Udostępnij na innych stronach

Bądź aktywny! Zaloguj się lub utwórz konto

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto

Zarejestruj nowe konto, to proste!

Zarejestruj nowe konto

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się

Zaloguj się, aby obserwować  

×