<?php
       $today=jdate("Y-m-d");
       //=======دالــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــر
        $select_Currency_dollar_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='2'  and date='$today' ORDER BY id limit 1";
		$select_Currency_dollar_query= $db ->query($select_Currency_dollar_sql);
		$select_Currency_dollar_row=$select_Currency_dollar_query ->fetch_array();
		$select_Currency_dollar=$select_Currency_dollar_row['rate'];
		$select_Currency_dollar=1;

       //=======افغـــــــــــــــــــــــانـــــــــــــــــــــــــــــــــــــــــــــــی
	   
	    $select_Currency_afghani_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='1'  and date='$today' ORDER BY id limit 1";
		$select_Currency_afghani_query= $db ->query($select_Currency_afghani_sql);
		$select_Currency_afghani_row=$select_Currency_afghani_query ->fetch_array();
		$today_finalAccount_AFN=$select_Currency_afghani_row['rate'];
		//در صورتیکه تاریخ روز در دسترس نبوداخرین تاریخ را انتخاب کند
		if($today_finalAccount_AFN==""){
		     echo "نرخ روز افغانی ثبت نیست";
		     $last_Currency_afghani_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='1' ORDER BY id limit 1";
		     $last_Currency_afghani_query= $db ->query($last_Currency_afghani_sql);
		     $last_Currency_afghani_row=$last_Currency_afghani_query ->fetch_array();
		     $today_finalAccount_AFN=$last_Currency_afghani_row['rate'];
		     
		 }
		
        //Change to dollar
		 
      //====تـــــومـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــان
	     $select_Currency_toman_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='5'  and date='$today' ORDER BY  id limit 1  ";
		 $select_Currency_toaman_query= $db ->query($select_Currency_toman_sql);
		 $select_Currency_toman_row=$select_Currency_toaman_query ->fetch_array();
		 $select_Currency_toman=$select_Currency_toman_row['rate'];
		 
		 if($select_Currency_toman==""){
		     echo "نرخ روز تومان ثبت نیست";
		     $last_Currency_totmat_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='5' ORDER BY id desc limit 1";
		     $last_Currency_toman_query= $db ->query($last_Currency_totmat_sql);
		     $last_Currency_toman_row=$last_Currency_toman_query ->fetch_array();
		     $select_Currency_toman=$last_Currency_toman_row['rate'];
		     
		 }
		 
		 
       //=======کـــالــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــدار
          $select_Currency_caldar_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='4'  and date='$today' ORDER BY  id limit 1  ";
		  $select_Currency_caldar_query= $db ->query($select_Currency_caldar_sql);
		  $select_Currency_caldar_row=$select_Currency_caldar_query ->fetch_array();
		  $select_Currency_caldar=$select_Currency_caldar_row['rate'];

           if($select_Currency_caldar==""){
		     echo "نرخ روز کالدار ثبت نیست";
		     $last_Currency_caldar_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='4' ORDER BY id desc limit 1";
		     $last_Currency_caldar_query= $db ->query($last_Currency_caldar_sql);
		     $last_Currency_caldar_row=$last_Currency_caldar_query ->fetch_array();
		     $select_Currency_caldar=$last_Currency_caldar_row['rate'];
		     
		 }		  

        //=======یـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــورو
		   $select_Currency_euro_sql="select * from crrencyrate  where counterCurrency='3' and baseCurrency='2'  and date='$today' ORDER BY id limit 1  ";
		   $select_Currency_euro_query= $db ->query($select_Currency_euro_sql);
		   $select_Currency_euro_row=$select_Currency_euro_query ->fetch_array();
		   $select_Currency_euro=$select_Currency_euro_row['rate'];
		   
            if($select_Currency_euro==""){
		     echo "نرخ روز یورو ثبت نیست";
		     $last_Currency_euro_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='4' ORDER BY id desc limit 1";
		     $last_Currency_euro_query= $db ->query($last_Currency_euro_sql);
		     $last_Currency_euro_row=$last_Currency_euro_query ->fetch_array();
		     $select_Currency_euro=$last_Currency_euro_row['rate'];
		     
		 }	

?>