我嘗試使用 intval 將我的字符串?dāng)?shù)組轉(zhuǎn)換為 INT 但是結(jié)果/返回總是int(1) 而數(shù)據(jù)庫(kù)值為 14698我的數(shù)據(jù)庫(kù):+-------+---------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+---------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || curr | char(3) | NO | | NULL | || rate | int(11) | NO | | 0 | |+-------+---------+------+-----+---------+----------------++----+------+-------+| id | curr | rate |+----+------+-------+| 1 | USD | 1 || 2 | IDR | 14698 || 3 | JPY | 112 || 4 | EUR | 1 || 5 | THB | 33 |+----+------+-------+這是我的 crudQuery.php 頁(yè)面: <?phprequire 'config.php';if (isset($_POST['save'])) { require_once 'functions.php'; $qty = $_POST['qty']; $qty = (int) $qty; $curr = $_POST['curr']; $price = $_POST['price']; $price = (int) $price; $rate = queryInt("SELECT rate FROM rate_master WHERE curr = '$curr'"); var_dump($rate);echo $rate[0];這是我的functions.php頁(yè)面:<?phprequire 'config.php'; function queryInt($query) { global $conn; $result = mysqli_query($conn, $query); $rows = []; while ($row = mysqli_fetch_assoc($result)) { $rows [] = intval($row); } return $rows; }然后, var_dump 的結(jié)果是:array(1) { [0]=> int(1) } 1我應(yīng)該做什么,以便從數(shù)據(jù)庫(kù)中返回值而不是 1 ?
1 回答
月關(guān)寶盒
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
while ($row = mysqli_fetch_assoc($result)) {
$rows [] = intval($row);
}
mysqli_fetch_assoc返回一個(gè)數(shù)組,您不能將一個(gè)數(shù)組“轉(zhuǎn)換為 int”,并期望它有一個(gè)有意義的結(jié)果。
intval($row)需要是intval($row['rate'])
- 1 回答
- 0 關(guān)注
- 143 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
