如何在PHP echo中添加数学?
我有一个网站,除了最低价格外,一切都很好。我的意思是,所有价格将根据所选货币而不是最低价格进行更改 最低价格是基于美元而不是其他货币正确显示的,我的意思是,如果我们将货币换成欧元,最低价格仍然显示在美元上,美元是默认货币 在我的Sql数据库中,我有一个表pt\u currency和列rate 在我的房间页面上,显示了以下PHP代码的最低价格:如何在PHP echo中添加数学?,php,mysql,sql,math,Php,Mysql,Sql,Math,我有一个网站,除了最低价格外,一切都很好。我的意思是,所有价格将根据所选货币而不是最低价格进行更改 最低价格是基于美元而不是其他货币正确显示的,我的意思是,如果我们将货币换成欧元,最低价格仍然显示在美元上,美元是默认货币 在我的Sql数据库中,我有一个表pt\u currency和列rate 在我的房间页面上,显示了以下PHP代码的最低价格: <?php echo $lowestPrice; ?> 这里是userdata和change currency的设置 funct
<?php echo $lowestPrice; ?>
这里是userdata和change currency的设置
function changeCurrency($id){
$this->db->where('id',$id);
$rs = $this->db->get('pt_currencies')->result();
$this->session->set_userdata('currencycode', $rs[0]->code);
$this->session->set_userdata('currencysymbol', $rs[0]->symbol);
$this->session->set_userdata('currencyname', $rs[0]->name);
$this->session->set_userdata('currencyrate', $rs[0]->rate);
}
}
如何根据所选货币(汇率)显示$lowestPrice?
我应该在上面的代码中添加什么公式,以显示基于所选货币的最低价格 好的,如果我正确理解了您的问题,您必须将db中的货币汇率放入php数组,然后使用php确定最低价格,如下所示:
$query = "SELECT rate FROM pt_currencie";
$result = mysqli_query($db_conn, $query);
$rate_arr = mysqli_fetch_fields($result);
$currLowestPrice = $lowestPrice;
foreach ($rate_arr as $rate) {
$tmpLowestPrice = $lowestPrice * $rate;
if($currlowestPrice > $tmpLowestPrice)
$currLowestPrice = $tmpLowestPrice;
}
因此,在for循环结束时,这应该至少为您提供以美元为单位的最低价格调整到货币汇率的最低价格(上面的代码可能需要为您的程序进行一些调整)您是否在某处有转换率?是的,我有,但里面没有与最低价格相关的内容。那么你想让我们做什么呢?给我一个代码,它将把默认的最低汇率转换成其他货币。我更新了我的问题,你可以看到什么是改变货币的功能你是如何做其他价格的转换?为什么你不能用同样的方法来降低价格呢?
$query = "SELECT rate FROM pt_currencie";
$result = mysqli_query($db_conn, $query);
$rate_arr = mysqli_fetch_fields($result);
$currLowestPrice = $lowestPrice;
foreach ($rate_arr as $rate) {
$tmpLowestPrice = $lowestPrice * $rate;
if($currlowestPrice > $tmpLowestPrice)
$currLowestPrice = $tmpLowestPrice;
}