Aller au contenu

tableaux et objets et tableaux


Sujets conseillés

Posté

Bonjour

Je souhaitrais insérer dans une table mysql le résultat d'une API qui m'est retourné sous forme d'objet avec des tableaux.

Voici précisément la structure que j'ai en retour


Result

stdClass Object
(
[GetGlobalTicksResult] => stdClass Object
(
[Outcome] => Success
[Identity] => Header
[Delay] => 0.359375
[Symbol] => FR0000130007.PA
[TickSet] => stdClass Object
(
[Tick] => Array
(
[0] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:02:00 AM
[Price] => 2.199
[Quantity] => 25707
[Change] => 0
[PercentChange] => 0
[High] => 2.199
[Low] => 2.197
[Open] => 2.198
)

[1] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:03:00 AM
[Price] => 2.199
[Quantity] => 1556
[Change] => 0
[PercentChange] => 0
[High] => 2.199
[Low] => 2.199
[Open] => 2.199
)

[2] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:04:00 AM
[Price] => 2.2
[Quantity] => 14640
[Change] => 0.001
[PercentChange] => 0.045
[High] => 2.2
[Low] => 2.199
[Open] => 2.199
)

[3] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:05:00 AM
[Price] => 2.198
[Quantity] => 786
[Change] => -0.002
[PercentChange] => -0.091
[High] => 2.198
[Low] => 2.197
[Open] => 2.197
)

[4] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:06:00 AM
[Price] => 2.202
[Quantity] => 90350
[Change] => 0.004
[PercentChange] => 0.182
[High] => 2.202
[Low] => 2.199
[Open] => 2.2
)

[5] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:07:00 AM
[Price] => 2.205
[Quantity] => 54512
[Change] => 0.003
[PercentChange] => 0.136
[High] => 2.207
[Low] => 2.202
[Open] => 2.202
)

[6] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:08:00 AM
[Price] => 2.204
[Quantity] => 16534
[Change] => -0.001
[PercentChange] => -0.045
[High] => 2.205
[Low] => 2.202
[Open] => 2.205
)

[7] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:09:00 AM
[Price] => 2.205
[Quantity] => 6843
[Change] => 0.001
[PercentChange] => 0.045
[High] => 2.205
[Low] => 2.203
[Open] => 2.203
)

[8] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:10:00 AM
[Price] => 2.207
[Quantity] => 1094
[Change] => 0.002
[PercentChange] => 0.091
[High] => 2.207
[Low] => 2.207
[Open] => 2.207
)

[9] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:11:00 AM
[Price] => 2.207
[Quantity] => 911
[Change] => 0
[PercentChange] => 0
[High] => 2.207
[Low] => 2.207
[Open] => 2.207
)

[10] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:13:00 AM
[Price] => 2.207
[Quantity] => 1111
[Change] => 0
[PercentChange] => 0
[High] => 2.207
[Low] => 2.205
[Open] => 2.205
)

[11] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:15:00 AM
[Price] => 2.207
[Quantity] => 1641
[Change] => 0
[PercentChange] => 0
[High] => 2.207
[Low] => 2.207
[Open] => 2.207
)

[12] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:16:00 AM
[Price] => 2.204
[Quantity] => 16315
[Change] => -0.003
[PercentChange] => -0.136
[High] => 2.207
[Low] => 2.204
[Open] => 2.207
)

[13] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:17:00 AM
[Price] => 2.207
[Quantity] => 9876
[Change] => 0.003
[PercentChange] => 0.136
[High] => 2.207
[Low] => 2.206
[Open] => 2.206
)

[14] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:18:00 AM
[Price] => 2.206
[Quantity] => 10100
[Change] => -0.001
[PercentChange] => -0.045
[High] => 2.206
[Low] => 2.206
[Open] => 2.206
)

[15] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:19:00 AM
[Price] => 2.207
[Quantity] => 163
[Change] => 0.001
[PercentChange] => 0.045
[High] => 2.207
[Low] => 2.207
[Open] => 2.207
)

[16] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:21:00 AM
[Price] => 2.207
[Quantity] => 2217
[Change] => 0
[PercentChange] => 0
[High] => 2.207
[Low] => 2.205
[Open] => 2.205
)

[17] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:24:00 AM
[Price] => 2.207
[Quantity] => 1473
[Change] => 0
[PercentChange] => 0
[High] => 2.207
[Low] => 2.206
[Open] => 2.206
)

[18] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:26:00 AM
[Price] => 2.207
[Quantity] => 6647
[Change] => 0
[PercentChange] => 0
[High] => 2.207
[Low] => 2.205
[Open] => 2.205
)

[19] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:27:00 AM
[Price] => 2.206
[Quantity] => 12751
[Change] => -0.001
[PercentChange] => -0.045
[High] => 2.207
[Low] => 2.206
[Open] => 2.207
)

[20] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:28:00 AM
[Price] => 2.205
[Quantity] => 6517
[Change] => -0.001
[PercentChange] => -0.045
[High] => 2.206
[Low] => 2.205
[Open] => 2.206
)

[21] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:29:00 AM
[Price] => 2.206
[Quantity] => 9053
[Change] => 0.001
[PercentChange] => 0.045
[High] => 2.206
[Low] => 2.206
[Open] => 2.206
)

[22] => stdClass Object
(
[Outcome] => Success
[Delay] => 0
[Time] => 9/16/2010 9:30:00 AM
[Price] => 2.207
[Quantity] => 107695
[Change] => 0.001
[PercentChange] => 0.045
[High] => 2.209
[Low] => 2.205
[Open] => 2.206
)

)

)

)

)

je souhaite insérer dans ma table les éléments les valeurs 'Price' et 'Time' qui se trouvent dans les objets Ticks de 1 à 22, c'est à dire:

$result->GetGlobalTicksResult->TickSet->Tick[$i]->Price;

$i allant de 1 à 22.

Je bute sur la façon de récupérer ces données et de les mettre dans un tableau qui me permette de faire une seule opération d'insert du type:


# INSERT INTO table histo ( code,price, time) VALUES
# (1,2.199 "9/16/2010 9:02:00 AM"),
# (2, 2.201,"9/16/2010 9:02:00 AM"),
# (3, 2.201,"9/16/2010 9:03:00 AM"),...

Auriez vous des suggestions afin d'avoir le traitement le plus cours ?

Merci

Posté

Salut,

Réponse " à l'arrache", non testé, un truc du genre :

$items = array();
for ($tick_num = 1; $tick_num <= 22; $tick_num++)
{
$price = $result->GetGlobalTicksResult->TickSet->Tick[$i]->Price;
$time = $result->GetGlobalTicksResult->TickSet->Tick[$i]->Time;
$items[] = implode(",", array ($tick_num, $price, "$time"));
}
$itemsStr = "(" . implode ("),(", $items) . ")";

Veuillez vous connecter pour commenter

Vous pourrez laisser un commentaire après vous êtes connecté.



Connectez-vous maintenant
×
×
  • Créer...