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条)

报告相同问题?

悬赏问题

  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题