Forum Moderators: coopster

Message Too Old, No Replies

i get asynchronous variables from xml i think

currency calculator

         

adek

6:18 am on Jul 14, 2011 (gmt 0)

10+ Year Member



Hi want to write cash currency calculator script like on site [bankier.pl ] which gets data from xml, but have problem. It almost works but when i set i.e. USD, rest value as conversion unit - co, and value cant get synchronous. I need some id to put, or next array? Help guys please show me some direct to solve this problem.
This is all script with all data, its working after cp and paste

data.xml:
 <data><tabela>
<item symbol="USD" jednostka="100" kupno="265"><![CDATA[pierwsza wartość]]></item>
<item symbol="EUR" jednostka="100" kupno="420"><![CDATA[druga wartość]]></item>
<item symbol="GBP" jednostka="1000" kupno="20"><![CDATA[trzecia wartość]]></item>
</tabela></data>



index.php:

$data = simplexml_load_file('data.xml');

foreach($data -> tabela as $tabela){
foreach($tabela -> item as $item){
}
}
echo "<select name=\"symbol\">";
foreach($tabela -> item as $item){
$array_xml = array($item);
//creating variables, but i dont know about doing it, not better is to still use $item['#*$!']? KUPNO=buy prize, JEDNOSTKA=conversion rate
$symbol = $item['symbol'];
$kupno = $item['kupno'];
$jednostka = $item['jednostka'];
foreach($array_xml as $value_xml) {
//option get element symbol from xml
echo "<option value=\"".$symbol."\">".$symbol."</option>";
//below i need to divide $kupno with $jendostka , and after do * with KWOTA=value write by user. It gest "kupno" and "jednostka" as last data from xml, i have to be something like $kupno[some id])?
$suma = $_POST['kwota'] * ($kupno / $jednostka);
}
}
echo "</select>";

//belwo i want to show chosed records after selecting USD, rest should get USD value, but always last data are selected, even i chose USD as first
echo " " .$kupno. " " .$symbol;
//pool to write value for user
echo "<form method=\"post\" action=\"index.php\">";
echo "<input type=\"text\" name=\"kwota\" value=\"".$kwota."\" maxlength=\"6\" size=\"6\" />";
echo "<input type=\"submit\" value=\"Wylicz\"/>";

print "<br>Price Value<b> " .$suma. " </b>zł";

coopster

3:09 pm on Aug 1, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, adek.

Are you asking how to retrieve the attributes from the xml data for use in your select options? Have you looked over the examples on the PHP manual page for SimpleXML? I think you will find information there to guide you.

[php.net...]