duanke3985 2014-06-14 14:53
浏览 112
已采纳

php echo在html中不起作用

This is my first code in php, so my problem might be so obvious. sorry if it is so easy :)

What I'm trying to do is that I am selecting some rows from my data base using

$rrows = Select ( "*" , $tbl_SubForum , null, "p");
$rrows->setFetchMode(PDO::FETCH_CLASS, 'subForum');

I know this works fine. Each row has the description of a sub forum, containing title and id. I am trying to show sub forum titles in table cells using this code:

 <table cellpadding=50px cellspacing=20px BORDER=0>
<?php
    $i=0; 
    while($rrow = $rrows->fetch()){
    var_dump($rrow);
?>
<tr>
<td class='subforum' id='subforum1'>
<?php echo $rrow["title"]; ?><br>
Sub forum manager<br>

Posts: 200<br>
    Active users: 50<br>
</td>
</tr>
<?php 
    $i++;
}

    ?>

the line echo $rrow["title"]; doesn't work and so the page is empty, except for the result of the first var_dump First var_dump of the first $rrow shows:

enter image description here

as you can see, there actually is a title field in the array and there is only one var_dump so the while loop doesn't work anymore!

why is this happening?

  • 写回答

1条回答 默认 最新

  • dongyinzheng6572 2014-06-14 14:55
    关注

    Because $rrow is an object rather than an array, you have to use $rrow->title to access its data member.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?