0

我正在尝试建立一个CMS。我不想使用模板,我想做一些更高级的事情,因此我需要制作许多表格和许多行来达到相同的效果,因为每个页面都有不同的设计。

因此,在 index.php 中有 7 个文本字段,我希望能够通过 RTE 对其进行更新。所以我在我的数据库上创建了一个名为“page_hem1”的表,其中存在这 7 个文本字段,名称为“text1”、“text2”等。

然后我为此编写了一些基本代码:

// Query the body section for the proper page
$sqlCommand = "SELECT text1 FROM page_hem WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $body1 = $row["text1"];
    $body2 = $row["text2"];
    $body3 = $row["text3"];
    $body4 = $row["text4"];
    $body5 = $row["text5"];
    $body6 = $row["text6"];
    $body7 = $row["text7"];
} 
mysqli_free_result($query); 

我的问题是只有 $body1 变量被回显。为什么其他人没有?我究竟做错了什么?您应该知道,我还尝试为每个“$body”变量重复相同的代码序列,但也没有成功。也许我没有以正确的方式重复?

我能做些什么来回显所有 $body 的?

提前致谢!

4

4 回答 4

0

因为您只选择一列

错误(至少在这里,因为您需要其他列而不仅仅是 text1)

"SELECT text1  FROM page_hem ...

更好(得到所有,但避免)

"SELECT * FROM page_hem

正确的(只有你需要的)

"SELECT text1, text2, ... FROM page_hem
于 2013-09-24T12:20:33.290 回答
0

您需要检索 text1、text2 等。

$sqlCommand = "SELECT text1, text2, text3, text4, text5, text6, text7 FROM page_hem WHERE id='$pageid' LIMIT 1"; 
于 2013-09-24T12:22:17.470 回答
0

我认为唯一的错误是您只选择“text1”而不是所有文本列。

// Query the body section for the proper page
$sqlCommand = "SELECT text1, text2, text3, text4, text5, text6, text7 FROM page_hem WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $body1 = $row["text1"];
    $body2 = $row["text2"];
    $body3 = $row["text3"];
    $body4 = $row["text4"];
    $body5 = $row["text5"];
    $body6 = $row["text6"];
    $body7 = $row["text7"];
} 
mysqli_free_result($query); 
于 2013-09-24T12:25:52.233 回答
0
$sqlCommand = "SELECT text1, text2, text3, text4, text5, text6, text7 FROM page_hem WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $body1 = $row["text1"];
    $body2 = $row["text2"];
    $body3 = $row["text3"];
    $body4 = $row["text4"];
    $body5 = $row["text5"];
    $body6 = $row["text6"];
    $body7 = $row["text7"];
} 
mysqli_free_result($query); 
于 2013-09-24T12:32:47.890 回答