SELECT,WHERE MYSQL php表混乱

时间:2013-12-07 03:05:57

标签: php mysql

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。我该怎么做呢?

我需要重组我的桌子吗?还是多个mysqli_query?

1 个答案:

答案 0 :(得分:0)

你过分思考它。只需在查询的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];