Re: include as string
- From: "Tom M." <tmilewski@xxxxxxxxx>
- Date: Tue, 8 Apr 2008 07:11:57 -0700 (PDT)
On Apr 8, 10:10 am, "Tom M." <tmilew...@xxxxxxxxx> wrote:
On Apr 8, 8:13 am, Harris Kosmidhs <hkosm...@xxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
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 athttp://us3.php.net/include/Idid:
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
The reason it is not working is because you are not passing the $res
variable to the function.
function ListAlbums($result_set) {
ob_start();
include('views/albums_view.php');
$disp=ob_get_contents();
ob_end_clean();
return $disp;
}
You will now need to call that function:
ListAlbums($res);
That aside, why pass it if you don't seem to be using it in the
function anyway?
Nvm on that last question wasn't paying attention to the include.
.
- References:
- include as string
- From: Harris Kosmidhs
- Re: include as string
- From: Tom M.
- include as string
- Prev by Date: Re: include as string
- Next by Date: Re: asp.net to php
- Previous by thread: Re: include as string
- Next by thread: Re: include as string
- Index(es):
Relevant Pages
|