-2

i have combined javascript with php as shown in this code below. but is not working for me. it doesn't display the content. but it display the id when is requested.

function content24(){
          document.getElementById("dailypost_content").innerHTML = '<?php
          $query = "SELECT`dpost_content` FROM `daily_POST` WHERE `id`=      
                   '24'";
          $query_run = mysqli_query($host_connection, $query);  
          $query_row = mysqli_fetch_assoc($query_run);
          $content = $query_row['dpost_content'];
          echo '<span id "daily_caption"> <strong><u>Daily Inspiration</u>  
          </strong><br></span>';
          echo $content;
          ?>';
    }
r_batra
  • 400
  • 3
  • 14

2 Answers2

1

During a single HTTP request, the PHP is executed first on the server side, and then the javascript is executed on the client side. Therefore PHP can generated Javascript, but Javascript cannot generate PHP.

user803422
  • 2,636
  • 2
  • 18
  • 36
0

There is lots of thing wrong with what you are doing. I formatted the code you provided to be better. Keep the php out as much as possible. Please read up on the difference between client-side and server side programming.

    <?php 
      $query = "SELECT `dpost_content` FROM `daily_POST` WHERE `id`='24'";
      $query_run = mysqli_query($host_connection, $query);   
      $query_row = mysqli_fetch_assoc($query_run);
      $content = $query_row['dpost_content'];
    ?>
    function content24(){
      document.getElementById("dailypost_content").innerHTML = '<span id "daily_caption"> <strong><u>Daily Inspiration</u>  </strong><br></span>'+'<?php echo $content; ?>';
    }