donglu1472 2013-09-24 12:18
浏览 32
已采纳

无法回显PHP变量

I am trying to build up a CMS. I don't want to use a template, I want to do things a bit more advanced and therefore I will need to make many tables and many rows to achieve the same effect because each page will have a different design.

So, in the index.php I have 7 text fields that I want to be able to be updated via RTE. So I created a table called "page_hem1" on my database where those 7 text fields exist with the names "text1", "text2", etc.

Then I made some basic code for that:

// 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); 

My issue is that only the $body1 variable is being echoed. Why aren't the others? What am I doing wrong? You should know that I also tried to repeat the same code sequence for each and every single one of the "$body" variables, but it didn't work out neither. Perhaps i didn't repeat in the right way?

What can I do to echo all the $body's?

Thanks in advance!

  • 写回答

4条回答 默认 最新

  • dqusbxh44823 2013-09-24 12:25
    关注

    I think the only mistake is that you do select only "text1" not all text columns.

    // 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); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?