Guys, please tell me. There is a code that collects data of a particular country in the header on the site:
<?php $today = date("d/m/Y"); $fp = fopen('cb.xml', 'w'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http://www.cbr.ru/scripts/XML_daily.asp?date_req='.$today); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); fclose($fp); curl_close ($ch); ?> <script src="https://code.jquery.com/jquery-latest.js"></script> <script language="javascript" type="text/javascript"> jQuery(document).ready(function () { jQuery.ajax({ type: "GET", async : false, url: "cb.xml", dataType: "xml", success: Kurs }); function Kurs (xml) { jQuery(xml).find("Valute").each(function(){ if(jQuery(this).attr('ID')=='R01235') { usd = jQuery(this).find("Value").text(); jQuery(".rub span").text(parseInt(jQuery('.usd span').text())*parseInt(usd)); } }); } });</script> <script language="javascript" type="text/javascript">jQuery.noConflict();</script> <div id="banner_g1"> <?php $adres = $_SERVER['REQUEST_URI']; $parts = parse_url($adres); parse_str($parts['query'], $query); $need_id = $query['id']; include "php/dbc.php"; $dbcnx = @mysql_connect($DB_HOST,$DB_USER,$DB_PASSWORD); mysql_query("SET character_set_results = 'utf8'", $dbcnx); mysql_set_charset('utf8'); mysql_select_db($DB_NAME, $dbcnx); $bg_head_pic = mysql_query("SELECT * FROM law_content WHERE id = $need_id"); while($row=mysql_fetch_assoc($bg_head_pic)) { if ( $row['bg_head_pic']!= '' ) { echo '<img id="img_bb" alt="'.$row['logo_alt'].'" src="/images/'.$row['bg_head_pic'].'" />'; echo '</div><div id="banner_g2"><div id="banner_g2t1">'.$row['main_head_string'].'</div><marquee><div class="lenta-rbk">{module 177}</div></marquee><div id="banner_g2b">'; echo '<img alt="'.$row['logo_alt'].'" src="/images/'.$row['logo_pic'].'" />'; echo '<div id="banner_g2t2"><p>СТОИМОСТЬ ГОТОВОЙ КОМПАНИИ:</p><ul><li class="usd">от <span>'.$row['cost'].'</span> <span class="new_head_curr">'.$row['currency'].'</span></li>'; echo '<li class="rub">от <span>100</span> рублей (по курсу ЦБРФ)</li></ul><p><a href="/gotovie-kompanii-s-otkritim-schetom.html" target="">Компании со счетом</a></p></div></div>'; } } mysql_close($dbcnx); ?> </div> The code was written a couple of years ago in a hurry and we see that the central bank first parses. But in this case only the dollar is substituted! A piece answers for this:
if (jQuery(this).attr('ID')=='R01235') { usd = jQuery(this).find("Value").text(); jQuery(".rub span").text(parseInt(jQuery('.usd span').text())*parseInt(usd)); } There are also cases with EURO, it looks like this:
if (jQuery(this).attr('ID')=='R01239') { eur = jQuery(this).find("Value").text(); jQuery(".rub span").text(parseInt(jQuery('.eur span').text())*parseInt(eur)); } How can I make the EUR or USD variant be used within this code? PS: It depends on $ row ['currency'], which matters either "eur" or "usd".
Thank you in advance !
echo <li class="rub">от <span>100</span> рублей, which are then replaced by jquery, here, instead of100enter a currency check and a conversion rate. Rather, in the cycle, first count in rubles, and then substitute 100 for the desired value. To do this, you need to extract the values of the course from the xml-file obtained through theсurl. In general, the approach is bad. It is better to add a task tocronwhich once a day will receive the current exchange rate and stuff it into the database with the current date, and then you can read the current price directly in the request. - teran