gpt4 book ai didi

php - SELECT, WHERE MYSQL php 表困惑

转载 作者:行者123 更新时间:2023-11-30 00:57:21 25 4
gpt4 key购买 nike

Link to Mysql Table

我正在尝试让一个基本的网站显示表格中的信息以用作内容。我运行这个

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

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