0

Here is my array

[{"CurrencySymbol":"AU$","CurrencyDescription":"Austrailian Dollar","CurrencyRate":135.42,"CurrencyType":"AUD","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":135.42},{"CurrencySymbol":"£.","CurrencyDescription":"British pound sterling","CurrencyRate":212.62,"CurrencyType":"GBP","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":212.62},{"CurrencySymbol":"EURO","CurrencyDescription":"Euro","CurrencyRate":171.2,"CurrencyType":"EUR","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":171.2},{"CurrencySymbol":"¥.","CurrencyDescription":"Japanese yen","CurrencyRate":1.6809,"CurrencyType":"JPY","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":1.6809},{"CurrencySymbol":"SIN$","CurrencyDescription":"Singapore Dollar","CurrencyRate":107.3,"CurrencyType":"SGD","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":107.3},{"CurrencySymbol":"Rs.","CurrencyDescription":"Sri Lankan Rupees","CurrencyRate":1,"CurrencyType":"LKR","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":1},{"CurrencySymbol":"CHF","CurrencyDescription":"Swiss Frank","CurrencyRate":141.71,"CurrencyType":"CHF","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":141.71},{"CurrencySymbol":"US$.","CurrencyDescription":"United States dollar","CurrencyRate":135,"CurrencyType":"USD","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":137}]

i need to show 'CurrencySymbol' values in a HTML selection and I am using PHP. please help because i am new to PHP.

Below is what i tried. it is giving only an empty selection

     $jsonres = '[{"CurrencySymbol":"AU$","CurrencyDescription":"Austrailian Dollar","CurrencyRate":135.42,"CurrencyType":"AUD","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":135.42},
            {"CurrencySymbol":"£.","CurrencyDescription":"British pound sterling","CurrencyRate":212.62,"CurrencyType":"GBP","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":212.62},
            {"CurrencySymbol":"EURO","CurrencyDescription":"Euro","CurrencyRate":171.2,"CurrencyType":"EUR","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":171.2},
            {"CurrencySymbol":"¥.","CurrencyDescription":"Japanese yen","CurrencyRate":1.6809,"CurrencyType":"JPY","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":1.6809},
            {"CurrencySymbol":"SIN$","CurrencyDescription":"Singapore Dollar","CurrencyRate":107.3,"CurrencyType":"SGD","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":107.3},
            {"CurrencySymbol":"Rs.","CurrencyDescription":"Sri Lankan Rupees","CurrencyRate":1,"CurrencyType":"LKR","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":1},
            {"CurrencySymbol":"CHF","CurrencyDescription":"Swiss Frank","CurrencyRate":141.71,"CurrencyType":"CHF","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":141.71},
            {"CurrencySymbol":"US$.","CurrencyDescription":"United States dollar","CurrencyRate":135,"CurrencyType":"USD","RequestDate":"\/Date(1408041000000)\/","PolicyId":"","QuotationId":0,"SellingRate":137}]';

        // var_dump( $jsonres['Data']);         
 echo '<select>';
foreach($jsonres->Data as $option){
echo '<option value=' . $option->CurrencySymbol. '>' . $option->CurrencySymbol. '</option>';  
 }
echo '</select>';
5
  • What have you tried already? Paste some code and we can point you to the right direction. foreach would be a good starting point to try. Commented Aug 15, 2014 at 5:29
  • Please explain in brief Commented Aug 15, 2014 at 5:29
  • 1
    You can't just come here and ask someone to write your code for you. Please show what you have tried and what isn't working for you. stackoverflow.com/help/how-to-ask Commented Aug 15, 2014 at 5:29
  • $obj=json_decode($yourStringAbove); echo $obj->CurrencySymbol; Commented Aug 15, 2014 at 5:32
  • Duplicate of your own previous question, Read Json Object Using PHP Commented Aug 15, 2014 at 5:39

3 Answers 3

1

You need to decode the json data first. Use: $jsonres = json_decode( $jsonres );

Then:

foreach ($jsonres as $key => $value) {
echo '<option value=' . $value->CurrencySymbol. '>' . $value->CurrencySymbol. '</option>';
}
Sign up to request clarification or add additional context in comments.

Comments

0

As stated in my comment on your initial question, i will not write the code for you as you did not even try to do it yourself first.

But what you need to do is decode the json and then loop through that array outputting the currency symbol in a html select.

1 Comment

Sorry for not putting my code earlier. I just edited my question and now you can see what i have tried
0

You can do something like...

foreach( $this->currency_array as $key => $value) {
    echo $value['CurrencySymbol'];
}

where...

$currency_array = your array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.