Q - อยากทราบวิธีคำนวณค่าสกุลเงินครับ

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderators: mindphp, ผู้ดูแลกระดาน

User avatar
thatsawan
PHP VIP Members
PHP VIP Members
Posts: 27170
Joined: 31/03/2014 10:02 am
Contact:

Re: Q - อยากทราบวิธีคำนวณค่าสกุลเงินครับ

Post by thatsawan »

เช็คว่ามันทำงาน

Code: Select all

if ($currency_id == 'USD') {
            $value = $text_box * $v['selling']; 
หรือยังด้วย
User avatar
birdkritsna
PHP Super Member
PHP Super Member
Posts: 234
Joined: 16/09/2019 9:57 am

Re: Q - อยากทราบวิธีคำนวณค่าสกุลเงินครับ

Post by birdkritsna »

thatsawan wrote:error ให้แปะ code error ลงมาเลยค่ะ

ลองศึกษา number_format
https://www.mindphp.com/%E0%B8%84%E0%B8 ... mat().html

เช็คดูมีค่าส่งมาครบหรือป่าว
Error เหมือนกันครับ ผมลอง echo ค่า $value เดี่ยวๆเลย ก็ไม่ได้คครับ
Notice: Undefined variable: number in D:\xampp\htdocs\joomla_testing\tools\exchange_rate\index.php on line 289
0.00 GBP

Code: Select all

 <?php echo $english_format_number = number_format($number, 2, '.', '')." ".$list_box_b; ?>
User avatar
thatsawan
PHP VIP Members
PHP VIP Members
Posts: 27170
Joined: 31/03/2014 10:02 am
Contact:

Re: Q - อยากทราบวิธีคำนวณค่าสกุลเงินครับ

Post by thatsawan »

แปะ code ทั้งหมดมาดูด้วย ตอนเเรกไม่มี $number ?
User avatar
birdkritsna
PHP Super Member
PHP Super Member
Posts: 234
Joined: 16/09/2019 9:57 am

Re: Q - อยากทราบวิธีคำนวณค่าสกุลเงินครับ

Post by birdkritsna »

thatsawan wrote:แปะ code ทั้งหมดมาดูด้วย ตอนเเรกไม่มี $number ?
ผมใช้เป็น $value แล้วครับ

อันนี้โค๊ดทั้งหมดครับ

Code: Select all

<?php

require_once'conn.php';
include '../head_html.php';
include '../config.php';
include '../header.php';

?>
<link rel="stylesheet" href="../css/color.css">


<meta property="og:url"           content="<?php echo ((array_key_exists('HTTPS', $_SERVER) && $_SERVER["HTTPS"] == "on") ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>"/>
<meta property="og:type"          content="website" />
<meta property="og:title"         content="<?php echo $lang_programexchangerate; ?>" />
<meta property="og:description"   content="<?php echo $lang_believethatkk; ?> " />
<meta property="og:image"         content="https://www.mindphp.com/images/content/Tool/M-Tax-Calculator.png" />
<meta property="og:image:alt"     content="<?php echo $lang_programexchangerate; ?>" />
<meta name="keywords"             content="home loan, home loan Calculator , โปรแกรม Pace, โปรแกรมคำนวณสินเชื่อบ้าน, ภาษีหัก ณ ที่จ่าย" />
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script src='https://kit.fontawesome.com/a076d05399.js'></script>


<script type="application/ld+json">
    {
    "@context": "http://schema.org",
    "@type": "SoftwareApplication",
    "name": "Homeloan Calculator",
    "image": "https://www.mindphp.com/images/info/mindphp-logo-v40.png",
    "description": "",
    "applicationCategory": "http://schema.org/GameApplication",
    "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "4.3",
    "ratingCount": "31242"
    },
    "offers": {
    "@type": "Offer",
    "price": "1.00",
    "priceCurrency": "USD"
    }
    }
</script>

<?php 
include '../PHP-Pagination-master/Pagination.class.php';

$page = 1;
if(isset($_GET['page'])){
	$page = $_GET['page'];
}



// ดาต้าเบสที่ปิดไว้ลอง รันหน้าเปล่าๆดูก่อน

$row = 10;
$total_data = "SELECT*FROM $data";
$result_1 = mysqli_query($con, $total_data);
$total = mysqli_fetch_row($result_1);
$total_data = $total[0];
$Pagination = new Pagination($page,$total_data);
$Pagination->parse();
$start = ($page - 1)* $row;



?>

<div class="container">
    <div class="col-md-12">
        <div class="row">
            <!--pathway-->            
            <div class="btn-group btn-breadcrumb">
                <a href="#" class="btn btn-default"><?php echo $lang_youarehere;?>:</a>
                <a href="https://www.mindphp.com/online-tools/mindphp-tools.html" class="btn btn-default"><?php echo $lang_tools;?></a>
                <a href="index.php?lang=<?php echo $lang; ?>" class="btn btn-primary"><?php echo $lang_exchange_rate;?></a>
            </div>

        </div><br>
    </div>
    <div class="row">


        <!--menu-->
        <div class="col-md-4">
            <?php include 'menu_sidebar.php'; ?>
        </div>
        <div class="col-md-8">
            <div class="col-md-12">
                <?php include 'script_facebook.php'; ?>
            </div>
        </div><br>
        <div class="col-md-8">
            <form method="post" action="" name="from">
                <div class="panel-group">
                    <div class="panel panel-primary" align="center">

                    
<!-- //เติม , (คอมมา) -->
<script src="jquerynum/jquery.number.js"></script>
<script type="text/javascript">
			
			$(function(){
				// Set up the number formatting.
				$('#moneys').number( true, 2 );
				
				// Get the value of the number for the demo.
				$('#get_number').on('click',function(){
					
					var val = $('#moneys').val();
					
					$('#number_container').slideDown('fast');
					$('#the_number').text( val !== '' ? val : '(empty)' );
				});
			});
		</script>
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://apigw1.bot.or.th/bot/public/Stat-ExchangeRate/v2/DAILY_AVG_EXG_RATE/"
    . "?start_period=2019-09-19&"
    . "end_period=2019-09-20&"
   ,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "x-ibm-client-id: 41a7650e-697b-4c11-968b-b982bac08687"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);
$response = json_decode(curl_exec($curl),1);
$data = $response["result"]["data"]["data_detail"];

curl_close($curl);
?>
                        <div class="panel-heading"><b><?php echo $lang_programexchangerate ?></b></div>
                        <div class="panel-body" >
                            <div class="input-group">
                                <span class="input-group-addon alert-info" id="basic-addon1"><?php echo $lang_name;?></span>
                                <input type="text" required name="name" class="form-control" autocomplete="off" placeholder="<?php echo $lang_enteryourname;?>" value="">
                            </div><br>
                            
                              <div >
                                        <input required type="number" class="form-control" id="inputPassword3" placeholder="<?php echo $lang_amount; ?>" name="num1">
                                    </div>
                            </div><br>
                            <div class="col-md-5">
                                        <div  class="form-group">
                                           <select name="list_box_a" id="list_box_a">
                                        <?php
                                          foreach($data as $v) {  ?>
                                                <option value="<?= $v['currency_id'] ?>"><?= $v['currency_name_th'] ?></option>
                                                <option value="THB"><?php echo $lang_usd ?>
                                           <!--<option value="<?= $v['selling'] ?>"><?= $v['selling'] ?></option>-->
                                        <?php
                                          } ?>
                                      </select> 
                                        </div>
                                    </div>
                           
                            <div class="col-md-2">
                                        <div  class="form-group">
                                               <select name="list_box_b" id="list_box_b">
                                        <?php
                                          foreach($data as $v) {  ?>
                                                    <option value="THB" selected=""><?php echo $lang_usd ?>
                                                    <option value="<?= $v['currency_id'] ?>"><?= $v['currency_name_th'] ?></option>
                                           <!-- <option value="<?= $v['selling'] ?>"><?= $v['selling'] ?></option>-->
                                         <?php
                                          } ?>
                                      </select> 
                                        </div>
                                    </div></span>
                                    <button class="btn btn-info" id="swap" name='swap' onclick="swapCurrency();"><i class='fas fa-retweet'  ></i></button>
                                    
                                
                            <br>
                            <script src='https://www.google.com/recaptcha/api.js'></script>
                        <div class="col-md-12">
                            <div align="center" class="g-recaptcha" required data-sitekey="<?php echo $keyrecaptcha; ?>"></div><br>
                        </div>
                            <br>
                            <input type="submit" name="submit" class="btn btn-success" value="<?php echo $lang_currency;?>" > 
                             
                            <input type="reset" name="reset" class="btn btn-warning" onclick="window.location = 'index.php?lang=<?php echo $lang; ?>';">
                            <?php
                            if (isset($_POST['g-recaptcha-response'])) {
                            $keyrecaptcha = $_POST['g-recaptcha-response'];
                            if (empty($keyrecaptcha)) {
                            if (isset($_POST['g-recaptcha-response'])) {
                            $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretkeyrecaptcha . "&response=" . $keyrecaptcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']), true);
                            ?>
                            <?php
                            if (!$keyrecaptcha) {
                            $missinginputsecret = $lang_automatedprogram;
                            ?>
                            <br><div align="center" class="errorip-color"><b><?php print_r($missinginputsecret) ?></b></div>
                            <?php
                            }
                            }
                            } else {
                                $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretkeyrecaptcha . "&response=" . $keyrecaptcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']), true);
                            if (isset($_POST['name']) && $response['success'] == true) {
                            echo '<input type = "hidden" name = "id" value = "' . $_POST['name'] . '" />';
                            }
                            
                            if (isset($_GET['id'])) {
                                echo '<input type = "hidden" name = "id" value = "' . $_GET['id'] . '" />';
                            }
                           
                                //
                            if (isset($_POST['submit'])) {
                                $submit1 = @$_POST['submit1'];
                                $name = $_POST['name'];
                                $text_box = $_POST['num1'];
                                $list_box_a = $_POST['list_box_a'];
                                $list_box_b = $_POST['list_box_b'];
                                //$a_currency['THB']=1;
                                
                                //selling คือ ค่าเงิน มาจาก api ธนาคาร
                               foreach($data as $v) { 
                                 $currency_id = $v['currency_id'];
                                 $selling = $v['selling'];
                                 } ?>                           
                           <?php              
                            //} if ($currency_id == 'THB') {
                            //$value = $a_currency[$list_box_b] / $selling[$list_box_a];
                            //ดอลล่าห์เป็นต่างประเทศ
                            }  if ($currency_id == 'USD') {
                                //$value = $selling[$list_box_b] / $selling[$list_box_a];
                                //$value = $text_box * $selling[$list_box_b];
                                $value = $text_box * $v['selling'];
                              
                            } else if ($currency_id == 'EUR') {
                                 $value = $text_box * $selling[$list_box_a];
                            //$value = $a_currencies[$list_box_b] / $a_currencies[$list_box_a];
                                
                            } else if ($list_box_a == 'GBP') {
                            $value = $text_box * $a_currencies[$list_box_a];
                           
                            } else {
                            }
                               
                               
                                date_default_timezone_set("Asia/Bangkok");
                                $datetime = time();
                                $date = date("Y-m-d  H:i:s", time());
                                $ip = $_SERVER["REMOTE_ADDR"];
                                ?>
                                <div align="center">
                                    <h3><?php echo $lang_userinformation;?></h3>
                                    <table class="table">                
                                        <tbody>

                                    <!--  TEST   --> 
                                    <!--  ชื่อ ผู้ใช้้งาน   -->
                                            <tr class="warning">
                                                <td align="right" width="50%">
                                                    <?php echo "ชื่อ : "; ?>
                                                </td>
                                                <td>
                                                <?php echo $name ?>
                                                </td>   
                                            </tr>
                                    <!--  สกุุลเงินที่เลือก  -->
                                    <tr class="active">
                                    
                                        <tr class="warning">
                                                <td align="right" width="50%">
                                                 <?php echo "$lang_from_currency :"; ?>
                                                  </td>
                                                     <td>
                                                         <?php echo $text_box . "   " . $list_box_a; ?>
                                        </td>
                                      
                                            <!--  สกุลเงินที่แปลง   -->
                                            <tr class="warning">
                                            <td align="right" width="50%">
                                            <?php echo  " สกุลเงินทีได้ :"; ?>
                                                </td>
                                            <td>
                                            <?php echo  number_format($value, 2, '.', '')." ".$list_box_b; ?>
                                                 </td>                        
                                            </tr>
                                         
                                      
                                                 <!--  เวลาที่ใช้งาน   -->
                                            <tr class="warning">
                                                <td align="right" width="50%">
                                                    <?php echo $lang_activetime." : "; ?>
                                                </td>
                                                <td>
                                                    <?php echo date("Y-m-d  H:i:s", time()); ?>
                                                  
                                                </td>                        
                                            </tr>
                                            <tr class="active">
                                                <td align="right" width="50%">
                                                    <?php echo $lang_your_ip." : "; ?>
                                                </td>
                                                <td>
                                                    <?php echo $ip; ?>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
<div id="container" style="width:90%; height:400px;"></div>       
                               <?php
                              //พอกดคำนวณ SQL ด้านล่างนี้คือ ตัวบันทึกลงฐานข้อมูล ว่าบันทึกอะไรบ้าง 
                              
                                $sql = "INSERT INTO $data (name,num1,from_currency,to_currency,num2,use_date,ip)" 
                               . "VALUES ('$name','$text_box','$list_box_a','$list_box_b','$value','$date','$ip')";
                               mysqli_query($con, $sql) or die($lang_datacannot);
                                  }
                                }
                               
                            ?>
                        </div>
                        <div align="right"><?php echo $lang_vercheckpace." ". $tax;?>&nbsp;&nbsp;&nbsp;
                        <br>
                        <br>
                        
                        </div>
                    </div>
                </div>                
            </form>
            

            <?php include 'tags.php'; ?>
            
            <div class="well2">
            <br>
            <ul>
                <b><?php echo $lang_step_how ?></b>
                <li><?php echo $lang_inputname_usere ?> <b><?php echo $lang_name?></b></li>
                <li><?php echo $lang_money_loan ?> <b> 
                <li><?php echo $lang_arr_inter?> <b> </li>
                <li><?php echo $lang_lang_putbtt?></li>
            </ul>
        </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 well well-lg">
            <?php include 'content.php'; ?>
        </div>
    </div>

    <!-- ข้อมูลการใช้งานล่าสุด -->
    <div class="row">
        <div class="col-md-12 table-responsive" align="center">
            <h3 align="center"><?php echo $lang_recentinformation;?></h3>
            <table class="table table-striped">
                <thead class="bg-primary" align="center">
                    <tr>
                        <th>
                            <p align="center"><?php echo $lang_no;?></p>
                        </th>
                        <th>
                            <p align="center"><?php echo $lang_name;?></p>
                        </th>
                        <th>
                            <p align="center"><?php echo $lang_amount;?></p>
                        </th>
                         <th>
                            <p align="center"><?php echo $lang_from_currency;?></p>
                        </th>
                        <th>
                            <p align="center"><?php echo $lang_to_currency;?></p>
                        </th>
                        
                        <th>
                            <p align="center"><?php echo $lang_date;?></p>
                        </th>
                        
                        </th>
                        <th>
                            <p align="center"><?php echo $lang_your_ip;?></p>
                        </th>
                        <th>
                            <p align="center"><?php echo $lang_showinformation;?></p>
                        </th>
                    </tr>
                </thead>






               <!-- ฐานข้อมูลแสดง ผู้ใช้งานล่าสุด -->
                <?php
               $sql = "SELECT * FROM $data ORDER BY id desc Limit $start,$row";
                    $result = mysqli_query($con, $sql);
                while ($fetch = mysqli_fetch_assoc($result)) {
                    ?>
                    <tr align="center">
                    <td>        
                            <?php echo $fetch['id']; ?>
                        </td>                        
                        <td>
                            <?php echo $fetch['name']; ?>
                        </td>
                         <td>
                            <?php echo $fetch['num1']; ?>
                        </td>
                        <td>
                            <?php echo $fetch['from_currency']; ?>
                        </td>
                        <td>
                            <?php echo $fetch['num2']." ".$fetch['to_currency']; ?>
                        </td>
                         <td>
                            <?php
                            echo  $fetch['use_date'];
                            ?>
                        </td>
                      
                       
                        <td>
                            <?php include 'ip.php'; ?>
                        </td>
                        <td>
                            <a href="show.php?id=<?php echo $fetch['id']; ?>&lang=<?php echo $lang; ?>">                                
                                <i class="glyphicon glyphicon-new-window"></i>
                            </a>
                        </td>
                    </tr>                    

                    <?php
                }
                ?>
            </table>



            <div class="text-center">
            	<nav aria-label="page navigation">
            		<?php echo $Pagination->parse(); ?>
            	</nav>
            
            </div>
            <input type="button" class="btn btn-primary" onclick="window.location = 'listhomeloan.php?lang=<?php echo $lang; ?>';" value="<?php echo $lang_seemore;?>">
        </div>
        
    </div>
</div>
<script>
    function swapCurrency(){
        var list_box_a = document.getElementById('list_box_a').value;
        var list_box_b = document.getElementById('list_box_b').value;
        document.getElementById('list_box_b').value = list_box_a;
        document.getElementById('list_box_a').value = list_box_b;
    }
</script>
                                    
<?php include '../footer.php'; ?>
Post Reply

Return to “Programming - PHP”

Who is online

Users browsing this forum: No registered users and 17 guests