www.webdeveloper.com
Results 1 to 9 of 9

Thread: php echo not working within database

  1. #1
    Join Date
    Dec 2011
    Posts
    5

    Question 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>
    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

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    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:

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

  3. #3
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by bionoid View Post
    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:

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

  4. #4
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    Quote Originally Posted by criterion9 View Post
    Missing an echo up there since the OP is just echoing all the contents:
    PHP Code:
    <div id="Chris-enlarge" style="width:900px;height:495px;overflow:hidden;">
    <?php echo readfile('profiles/profile_chris.html'); ?>
    </div>
    Even simpler (and more efficient) is
    PHP Code:
    <div id="Chris-enlarge" style="width:900px;height:495px;overflow:hidden;">
    <?php include('profiles/profile_chris.html'); ?>
    </div>
    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"
    Last edited by bionoid; 12-20-2011 at 07:50 AM.

  5. #5
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by bionoid View Post
    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"
    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).

  6. #6
    Join Date
    Dec 2011
    Posts
    5
    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

  7. #7
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    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.

  8. #8
    Join Date
    Dec 2011
    Posts
    5
    Hi yes sorry if Im not being clear... so I have put the page up on live server:

    http://www.directionfirst.com/websit...eare.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

  9. #9
    Join Date
    Jan 2009
    Posts
    3,346
    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...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles