0

I'm having a problem with this code snippet

document.getElementById("hello").innerHTML = "<?php $query = 'select * from 
subcategory_ref where category_no = " + a +"'; 
$result=mysqli_query($dbc,$query); echo '<select>';
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$id =$row['subcategory']; $name = $row['subcategory_name']; echo '<option> test </option>';};
echo '</select>'; ?>"

Var a is a number corresponding to a previous drop-down box. When alert(a) is used it alerts the value of var a but the innerHTML isn't reading it properly.

The reason I know there is a problem is if we replace the the 'a' in

subcategory_ref where category_no = " + a +"'; 

with

subcategory_ref where category_no = " + 1 +"'; 

The drop-down appears and is populated with the "test" option.

The value of var a is obtained like this

var a = document.getElementById("category").value;

Category being another drop-down box

However hard-coding a number inside the variable like this also doesn't work.

var a = 1;

Any ideas? We've been stuck on this for such a long time and it's unfortunately frustrating, any help would be greatly appreciated!

0 Answers0