我想从下表中检索信息并将其显示在文本字段
中我有一个名为items
的表。在items
中,我有字段item_number
,description
,item_id
,custom1
,custom2
,custom3
,{{1} }
如何回显或打印自定义字段的值?
custom4
答案 0 :(得分:0)
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sandbox";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT item_number, description, custom1, another_field FROM items";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<p>item_number: " . $row["item_number"]. "<br />description:" . $row["description"]. "<br />custom1: " . $row["custom1"] . "<br />another_field: " . $row["another_field"] . "</p>";
}
} else {
echo "0 results";
}
$conn->close();
?>
答案 1 :(得分:0)
这是我的代码
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT custom1, custom2, custom3 FROM ospos_items ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "custom:" . $row["custom1"]. " custom2: " . $row["custom2"]. " custom3 :" . $row["custom3"]. "<br>";
}
} else {
echo "0 results";
}
$ conn-&GT;关闭(); ?&GT;
并输出thid
我需要它只输出所选项目的海关字段,所以我添加
$ sql =“SELECT custom1,custom2,custom3 FROM ospos_items where item_id ='item_id'”;
因为这是唯一的数字,但它输出0结果我在想是否需要一个数组或某些东西让它工作,但我是新的PHP,我使用了表中列出的item_id