I have a problem with complicated JS determination of exact item:
this PHP/SQL code:
$prod = array();
$vys = mysqli_query($db,"SELECT * FROM produkty ORDER BY nazev");
while ($arr = mysqli_fetch_assoc($vys)) {
$prod[$arr['id_typu']][] = "<option value='".$arr['id_produktu']."'>".$arr['nazev']."</option>";
$polozky[$arr['id_typu']]= '<select name=idp[]>' . implode(' ', array_values($prod[$arr['id_typu']])) . '</select>';
}
this JS code:
<script type=\"text/javascript\">
function polozky(divName, typ){
var newdiv = document.createElement('div');
newdiv.innerHTML = \" $polozky[1] \"
document.getElementById(divName).appendChild(newdiv);
}
</script>
and this HTML code:
<form method='post'><fieldset>
<button type='button' name='typ' value='1' onclick=\"polozky('dynamicInput', '1');\">Add produkty from cathegory 1</button>
<button type='button' name='typ' value='2' onclick=\"polozky('dynamicInput', '2');\">Add produkty from cathegory 2</button>
<button type='button' name='typ' value='3' onclick=\"polozky('dynamicInput', '3');\">Add produkty from cathegory 3</button>
<div name='dynamicInput'></div>
</fieldset></form>
The problem is, that for each cathegory I want to generate (for every value of button) its own content. Using that $polozky[1-3] I'm querying the database for the right items of that cathegory (for items WHERE id_type=value in bracket). And I can't imagine that for 100 cathegories, I need to manually insert 100 times $polozky[1-100]. There must be some trick to do this. Somehow to store the value or some usage of that parameter (i was thinking of some $num=typ inside of the JS branch, but it's not possible due to the different processing type of JS and PHP).
Do you know, what to do please? ;) Thank you