0

I am wanting to automatically display content from my databse within an iframe as it acts as the body content which was submitted when creating the doc.

I am trying to insert with a mix of JS Php like so:

<iframe name="editor" id="editor" class="doc_body" ></iframe></div>

<script> 
var iframe = document.getElementById('editor'), 
iframedoc = iframe.contentDocument || iframe.contentWindow.document; 
iframedoc.body.innerHTML ="<?php echo ($row[2]); ?>"; 
</script> 

I know that I am indexing correctly because if I echo this out of the JS it will output the correct row.

Unless the syntax is wrong above?

UPDATED

so after some messing around it would appear that there is a conflict between this:

    <?php    


    $q = "SELECT * FROM cats";
    $r = mysqli_query ($dbc, $q); // Run the query.


    // FETCH AND PRINT ALL THE RECORDS
    while ($row = mysqli_fetch_array($r)) {
    echo '<ul><li><label><input type="checkbox" <?php if ($checked == 1) echo "checked"; name="cat_id[]" value="' . $row['cat_id'] . '"> ' . $row["cat_name"] . '</label></li></ul>';
    }

    ?>

And the above, If I remove this above the content shows but if I include it - it takes it away?

PhpDude
  • 1,542
  • 2
  • 18
  • 33

1 Answers1

1

your problem is solved right here ;)

Insert content into iFrame

<iframe name="editor" id="editor" class="doc_body" ></iframe></div>

<script> 
  var doc = document.getElementById('editor').contentWindow.document;
  doc.open();
  doc.write(<?php echo ($row[2]); ?>);
  doc.close();
</script> 

hope it helps, working fiddle can be found in the link i posted above

Community
  • 1
  • 1
messerbill
  • 5,499
  • 1
  • 27
  • 38