作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试让一个基本的网站显示表格中的信息以用作内容。我运行这个
$result = mysqli_query($conn,"SELECT cont_id, cont_text FROM content") or die("Error in the consult.." . mysqli_error($conn));
$row = mysqli_fetch_array($result);
每个 page_location 都是网站上的一个页面。我想做一些类似的事情
<?php echo $row['cont_text'] WHERE cont_id = 15; ?>
我知道这是不对的,但在页面下方我会从新的 cont_id 中回显 cont_text。我该怎么办?
我需要重新整理我的 table 吗?或者多个mysqli_query?
最佳答案
你想太多了。只需在查询的 where 子句中使用 cont_id
运行一个查询即可:
$result = mysqli_query($conn,"SELECT cont_text FROM content WHERE cont_id = 15") or die("Error in the consult.." . mysqli_error($conn));
$row = mysqli_fetch_array($result);
echo $row['cont_text'];
编辑
根据您的评论尝试以下操作:
$result = mysqli_query($conn,"SELECT cont_id , cont_text FROM content") or die("Error in the consult.." . mysqli_error($conn));
$content = array();
while($row = mysqli_fetch_array($result)) {
$content[$row['cont_id']] = $row['cont_text'];
}
echo $content[15];
关于php - SELECT, WHERE MYSQL php 表困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20437078/
我是一名优秀的程序员,十分优秀!