0
       <?php foreach($medias as $media):
        if (strpos($media->type, 'image') !== false) { ?>
          <article>
                <a href="mediapage.php?id=<?php echo $media->id; ?>">
                    <img src="<?php echo $media->image_path(); ?>" width="200" />
                </a>
            <hgroup>
                <h3><?php echo $media->caption; ?></h3>
            </hgroup>
            <p><?php echo $media->caption; ?></p>
          </article>
        <?php } else { ?>
        <article>
            <video controls>
                <source src="<?php echo $media->image_path(); ?>">
                Your browser does not support HTML5 video.
            </video>
            <hgroup>
                <h3><?php echo $media->caption; ?></h3>
            </hgroup>

MY code works fine as a php file. The problem is I need it to work when I retrieve it from mysql. The php code works fine on its own and when in between tags. My problem is the code inside an opening tag like the a href and the img src. How do I get the php to turn on and off inside these tags? Also the code won't call the object attribute, it turns off.

what the dom shows

la1450
  • 1
  • 2

1 Answers1

0

You have to create an .htaccess file and add the following directive to it:

# allows HTML files to be interpretted as PHP files
AddType application/x-httpd-php .html

The .htaccess file should be saved to your web root. This will allow PHP code in HTML files to be interpreted and processed properly.

Jay Blanchard
  • 32,731
  • 15
  • 70
  • 112
  • I am using xammp to get everything working. I opened apache httpd.conf and added AddHandler application/x-httpd-php .html. The php code runs properly if saved as .html. My problem is when I save the page to sql and retrieve it. The code does not run properly. This is what shows in the DOM – la1450 Oct 16 '15 at 21:53
  • Save the page to SQL? That would seem to be a completely different question. – Jay Blanchard Oct 16 '15 at 21:54