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 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)