include as string



Hello,

I have a php file like the following:
<?php foreach($res as $album) { ?>
<div class="albums">
<div class="left albumimage">
<a href="album/<?php echo $album["id"] ;?>">
<img alt="<?php echo $album["title"]; ?>" title="<?php echo $album["title"]; ?>" src="<?php echo "../".$photosdir.$album["photo"]; ?>">
</a>
</div>
<?php } ?>

I call this file from a function :
function ListAlbums($res) {
include('views/albums_view.php');
}

Before this I have opened a sql query and $res has the resultset. So my pages renders correctlly for each of the rows on $res.

But now I want for this file not to be printed directly (as include does) but rather store the output to a string. As I read at http://us3.php.net/include/ I did:

function ListAlbums($res) {
ob_start();
include('views/albums_view.php');
$disp=ob_get_contents();
ob_end_clean();
return $disp;
}

But $res now seems to be empty. Why doesn't this approach work? If I print_r($res) into my function it returns of course data.

thanks
.



Relevant Pages

  • Re: include as string
    ... Harris Kosmidhs wrote: ... I have a php file like the following: ... Before this I have opened a sql query and $res has the resultset. ... But now I want for this file not to be printed directly but rather store the output to a string. ...
    (comp.lang.php)
  • Re: include as string
    ... On Apr 8, 8:13 am, Harris Kosmidhs ... I have a php file like the following: ... Before this I have opened a sql query and $res has the resultset. ... return $disp; ...
    (comp.lang.php)
  • Re: mysql problem
    ... > Thus, res becomes null. ... mysql_store_resultalso returns a null pointer if reading of the ... An empty result set is returned if there are no rows returned. ...
    (comp.lang.c)
  • Re: Death to tuples!
    ... Antoon Pardon a écrit: ... but I think that each occurence returning the same (initially empty) ... def f: ... return res ...
    (comp.lang.python)