Jump to content

PHP array processing to mysql


cb154

Recommended Posts

Hi, I am making a call and getting an array returned which appears like this

 

Result

 

stdClass Object

(

    [GetHistoricalCrossRatesRangeResult] => stdClass Object

        (

            [Outcome] => Success

            [identity] => IP

            [Delay] => 0.016

            [symbol] => USDEUR

            [From] => stdClass Object

                (

                    [symbol] => USD

                    [Name] => United States Dollar

                )

 

            [To] => stdClass Object

                (

                    [symbol] => EUR

                    [Name] => Euro

                )

 

            [CrossRates] => stdClass Object

                (

                    [CrossRateItem] => Array

                        (

                            [0] => stdClass Object

                                (

                                    [Date] => 2/16/2010

                                    [First] => 0.73539415207652

                                    [Last] => 0.72663855924982

                                    [High] => 0.73589741835227

                                    [Low] => 0.72569994084434

 

 

I have written some code to put this into a mysql database but I am having some problems. The date is not being returned and the decimal numbers are being rounded. I am a newbie and my code looks like this

$max = sizeof($result->GetHistoricalCrossRatesRangeResult->CrossRates->CrossRateItem);

for ($i = 0; $i<=$max; $i++)
{
$Ccy = $result->GetHistoricalCrossRatesRangeResult->Symbol;
$TSDate = $result->GetHistoricalCrossRatesRangeResult->CrossRates->CrossRateItem->$i->Date;
$First = (double)$result->GetHistoricalCrossRatesRangeResult->CrossRates->CrossRateItem->$i->First;
$Last = (double)$result->GetHistoricalCrossRatesRangeResult->CrossRates->CrossRateItem->$i->Last;
$High = (double)$result->GetHistoricalCrossRatesRangeResult->CrossRates->CrossRateItem->$i->High;
$Low = (double)$result->GetHistoricalCrossRatesRangeResult->CrossRates->CrossRateItem->$i->Low;




$query = "Insert into FXRates (CCy, TSDate, First, Last, High, Low)
		values ('$Ccy', '$TSDate', $First, $Last, $High, $Low)";

mysql_query ($query) or die ("Query failed: " . mysql_error() . " Actual Query: " . $query);

}

 

when i check my query I am getting

 

Insert into FXRates (CCy, TSDate, First, Last, High, Low) values ('USDEUR', '', 0, 0, 0, 0)

 

can anyone point out my mistake please.

Link to comment
https://forums.phpfreaks.com/topic/192406-php-array-processing-to-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.