Page 1 of 1

Problem JS script with php code

Posted: 08 May 2019, 16:39
by JanMolendijk
I try to add this script to build a energy-low-mode dark-mode
But It only succeed with one item but I would like to have it with all items 6 rows

<?php echo $row['post_id']?>

elem5<?php echo $row['post_id']?> = document.querySelector(".img4<?php echo $row['post_id']?>");

Code: Select all

 <script> 
        function setBg2() { 
            elem = document.querySelector(".column"); 
            elem1 = document.querySelector(".column1"); 
            elem2 = document.querySelector(".column2");
 
 elem4 = document.querySelector(".venster");

 elem5<?php echo  $row['post_id']?> = document.querySelector(".img4<?php echo  $row['post_id']?>");


            elem.style.background = "black"; 
 elem1.style.background = "black"; 
 elem2.style.background = "black"; 
    
  elem4.style.background = "black"; 
  elem5<?php echo  $row['post_id']?>.style.background = "black"; 

  elem.style.color = "gray"; 
  elem1.style.color = "gray"; 
  elem2.style.color = "gray"; 
  elem4.style.color = "gray"; 

} 
    </script> 
    
    <tr>
  <td bgcolor=#ffffff>
  </td>
  <th bgcolor="#FFFFFF">
   <span style="cursor: crosshair">
    <a href="#" onmouseover="setBg0()"> <t style="color: #ffffff; background-color: #ffffff">w</t></a>
    <a href="#" onmouseover="setBg1()"><t style="color: #a6a6a6; background-color: #a6a6a6">g</t></a>
    <a href="#" onmouseover="setBg2()"><t style="color: #000000; background-color: #000000">d</t></a>
   </span>
  </th>
 </tr>
    
& I place it in this script

Code: Select all

    <?php
    // Include the database configuration file
    include 'dbConfig.php';
    
    // Get records from the database
    $query = $db->query("SELECT *, SUBSTRING(`post_text`, 1, 150)   AS post_text  FROM w3_post where not privacy='hide' ORDER BY post_id DESC LIMIT 6");
      }

    if($query->num_rows > 0){ 
        while($row = $query->fetch_assoc()){ 

include 'badwords-busy.php';
 
   $postID = $row['post_id'];
    ?>   

<br><br>
    <?php } ?>
    <div class="show_more_main" id="show_more_main<?php echo $postID; ?>">
        <span id="<?php echo $postID; ?>" class="show_more" title="Load more posts">Show more</span>
        <span class="loding" style="display: none;"><span class="loding_txt">Loading...</span></span>
    </div>
<br><br><br><br>
    <?php } ?>
</div>

Problem JS script with php code

Posted: 09 May 2019, 05:44
by Admin
I do not understand the script because the code is not complete.
You not have html code with classes used in the setBg2() function; and it is a mix of js-php code that cannot be tested.

Problem JS script with php code

Posted: 11 May 2019, 05:23
by JanMolendijk
I apologize the script is a bit too big, and it's only 1 item I don't get fixed but I'll leave it that way .... Thanks for the feedback