0

I am having issues with displaying my database products from a certain category when I click a link that calls a script function.

<li><button onclick="GPUclick()">GPU</button></li>

This is where I call my script to filter my products only to graphics cards, and I have that done with script / html like so:

function GPUclick() {
     document.getElementById("parts").innerHTML = "<main> " +
                                                " <img src='Images/760_ASUS.png' class='myClass'> " +
                                                " <span class='myClass2'><ul><li>Asus GeFroce GTX 760</li><li>PCI-E 3.0, 2048MB VRAM</li><li>Price: £161.99</li></ul></span> "+ 
                                                " <img src='Images/outOfStock.png' class='myClass3' alt='No stock'> " + 
                                                "</main>";
}

however now that I am using a database I need to filter through products that are being added into the database instantly.

I have a mysqli query that deals with the SQL:

$test = mysqli_query($conn, "SELECT * FROM products WHERE Category_ID = 2

I am just struggling now with printing anything out relating to that SQL command, I can do a in the javascript but that isn't really leading me to anything I can use or figure out without help and after looking for a while I can't find anything to help me either.

I appreciate any help / pushes in the right direction, thanks in advance.

I have tried adding "<?php echo $test['product_ID']?> " + to my JS function but that either outputs nothing or breaks the JS from even working.

jayelj
  • 47
  • 6

1 Answers1

0

You cannot use PHP in Javascript; All PHP content must be in a PHP file and PHP is serverside, so all PHP is proceed on the Server. In php use echo $test; or i would try this Php code:

<?php
echo "<script> var test = $test </script>" 
?>
Mikdore
  • 699
  • 5
  • 16