gpt4 book ai didi

php - 将表列中的 DEC 值转换为十六进制

转载 作者:行者123 更新时间:2023-11-29 11:31:51 25 4
gpt4 key购买 nike

实际上我猜这个问题是重复的,但我不明白我的 SQL 代码有什么问题。我的错误是

Notice: Undefined index: CI in C:\wamp\www\LOCATIONVIEWER\exampleDB.php on line 30.

我需要将列的所有十进制值转换为十六进制值。帮我做一下...:)

这是我的代码:

<html>
<head>
<title>test</title>
</head>

<body>
<?php


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "locationviewer";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//CI is a column name of the table
$sql = "SELECT CONV(CI,10,16) FROM locationdata";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "CI: " . $row["CI"]."<br>";
}
} else {
echo "0 results";
}
$conn->close();


?>

</body>

</html>

最佳答案

您应该更改以下代码:

$sql = "SELECT CONV(CI,10,16) FROM locationdata";

$sql = "SELECT CONV(CI,10,16) AS `CI` FROM locationdata";

发生这个问题是因为 php 无法看到 CI 索引,并且当前索引类似于 CONV(CI,10,16)

关于php - 将表列中的 DEC 值转换为十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37268913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com