0

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
  • 1
    $rrow is an object and not an array; try $rrow->title instead. Commented Jun 14, 2014 at 14:55

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

wow YES! thank you!! I knew it was something simple that I wasn't aware of! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.