网上有很多教程关于使用php进行数据插入和更新的,但是关于查询和分行显示的很少,能够在百度上面查询得到的也就是SELECT * FROM tablename 这样的,但我只想要几个相关参数咋办呢?结果经过好一阵猛如虎的操作才发现 需要的参数是要添加引号的就可以了,而不用那些繁琐的写法。比如下面的代码:
<?php
$servername = "localhost:3306";
$username = "kangkang";
$password = "123456";
$dbname = "kanggege";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}else{echo '连接成功!<br>';}
$sql = "SELECT 'order','question','always' FROM 9kinds";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["order"]. " - Name: " . $row["question"]. " " . $row["always"]. "<br>";
}
} else {
echo "0 结果";
}
$conn->close();
?>
|