在表列中将DEC值转换为十六进制

时间:2016-05-17 06:43:54

标签: php mysql sql mysqli

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

  

注意:未定义的索引:CI in   第30行的C:\ wamp \ www \ LOCATIONVIEWER \ exampleDB.php。

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

这是我的代码:

<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>

1 个答案:

答案 0 :(得分:1)

您应该更改以下代码:

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

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

发生这个问题是因为php看不到CI索引,当前索引就像CONV(CI,10,16)