/    Sign up×
Community /Pin to ProfileBookmark

php echo not working within database

Hi, I have a bit of a weird one… I have a site which holds sub nav pages within a simple database. On 1 of these pages I have a fancybox script that loads profiles by clicking on thumbnails located on a page called whoweare.php… these profiles are external html files and when the thumbnail is clicked it simply loads this page i.e.

[CODE]<div id=”Chris-enlarge” style=”width:900px;height:495px;overflow:hidden; “>
<?php
$fd = fopen(“profiles/profile_chris.html”, r);$content = fread($fd, filesize(“profiles/profile_chris.html”));fclose($fd);echo $content;?>
</div>[/CODE]

Now this all works fine when the page holding the profiles are not in the database but because this page has sub navs I put all these sub navs in a database and load them through the main page i.e. whoweare.php?pg=profiles but now when you click the thumbnails they are all blank… I even just tried a simple <?php echo “hi” ?> and still blank?

Why would this happen?

Hope someone can help

Thanks

Ben

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@bionoidDec 20.2011 — I don't see anything wrong with the code you submitted, as long as the file your reading is there.

An easier way to read that file would be to use readfile, instead of opening, reading and closing the file:

[code=php]<div id="Chris-enlarge" style="width:900px;height:495px;overflow:hidden;">
<?php readfile('profiles/profile_chris.html'); ?>
</div>[/code]
Copy linkTweet thisAlerts:
@criterion9Dec 20.2011 — I don't see anything wrong with the code you submitted, as long as the file your reading is there.

An easier way to read that file would be to use readfile, instead of opening, reading and closing the file:

[code=php]<div id="Chris-enlarge" style="width:900px;height:495px;overflow:hidden;">
<?php readfile('profiles/profile_chris.html'); ?>
</div>[/code]
[/QUOTE]

Missing an echo up there since the OP is just echoing all the contents:
[code=php]<div id="Chris-enlarge" style="width:900px;height:495px;overflow:hidden;">
<?php echo readfile('profiles/profile_chris.html'); ?>
</div>[/code]

Even simpler (and more efficient) is
[code=php]
<div id="Chris-enlarge" style="width:900px;height:495px;overflow:hidden;">
<?php include('profiles/profile_chris.html'); ?>
</div>
[/code]
Copy linkTweet thisAlerts:
@bionoidDec 20.2011 — Missing an echo up there since the OP is just echoing all the contents:
[code=php]<div id="Chris-enlarge" style="width:900px;height:495px;overflow:hidden;">
<?php echo readfile('profiles/profile_chris.html'); ?>
</div>[/code]

Even simpler (and more efficient) is
[code=php]
<div id="Chris-enlarge" style="width:900px;height:495px;overflow:hidden;">
<?php include('profiles/profile_chris.html'); ?>
</div>
[/code]
[/QUOTE]


Clearly you have never used "readfile", as you do not need the echo.

Also, using include could have a different effect if there are PHP tags inside. And I highly doubt it will out perform "readfile" ?
Copy linkTweet thisAlerts:
@criterion9Dec 20.2011 — Clearly you have never used "readfile", as you do not need the echo.

Also, using include could have a different effect if there are PHP tags inside. And I highly doubt it will out perform "readfile" ?[/QUOTE]


Apologies. I remembered not using readfile for a reason and had forgotten what it was. Upon reflection I remembered that it doesn't buffer larger files well and can cause memory issues (encountered the issue specifically when handling streaming media buffering problems).
Copy linkTweet thisAlerts:
@Eddie_EauthorDec 20.2011 — Hi thanks for your responses but none of these worked... I even included the full URL to ensure the path is correct but the files is still blank... may be the way fancybox and the database clash... Im not sure
Copy linkTweet thisAlerts:
@bionoidDec 20.2011 — You have given use an incomplete picture to try and help you with.

But from what you have provided I do not see any immediate issues.

If the site is up and running but not functioning properly, maybe provide some links.

Good luck.
Copy linkTweet thisAlerts:
@Eddie_EauthorDec 21.2011 — Hi yes sorry if Im not being clear... so I have put the page up on live server:

http://www.directionfirst.com/website3/whoweare.php?pg=ot

The profile where I am trying to load the external file is through thumbnail Erica and when you click on this it goes blank and what I want it to look at is if you click Chris profile... This works because it has the code there and not as an include

Thanks

Ben
Copy linkTweet thisAlerts:
@criterion9Dec 21.2011 — We will need more code. It looks like you might need to adjust your logic a bit.

Example:

Split the profile loading part to a separate php (or section at least)

Adjust the URLs you were using before that pointed to html files and worked to instead point to the php file that loads appropriately.


Does that helps to clarify? I'm afraid we won't be able to help much more than that without seeing more code...
×

Success!

Help @Eddie_E spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...