Way out of my depth here but it nearly works so where am I going wrong (apart from trying it in the first place)
What I am trying to achieve is to take multiple values from a picklist then using a PHP function to create another picklist based on the results.
So far the code creates an SQL query string successfully and equally successfully passes the variable to the function but that is where it goes wrong. The function recognises the variable (it will display on screen) but will not function as a query. What is puzzling me more is that none of the usual string functions work on it - for example strlen() returns a length of 6. I am obviously missing something but that is the danger of running before you can walk when learning.
function changez(){
var px="select * from `goldsupplier` where goldsupplywhat like '%start%'";
var pl = document.getElementById("goldprods");
var xl= (pl.options.length-1);
for (i = 0; i < (pl.options.length); i++) {
if (pl.options.selected="true"){
wot=pl.options.value;
if (wot=="a"){
px=px+" or goldsupplywhat like '%a%'";
}
if (wot=="b"){
px=px+" or goldsupplywhat like '%b%'";
}
if (wot=="c"){
px=px+" or goldsupplywhat like '%c%'";
}
}
}
document.getElementById("moreinputs").innerHTML = "<?php pickproductsupply('"+px+"'); ?>";
}
the PHP code
function pickproductsupply($prods){
$sql=$prods;
echo $sql;# DISPLAYS THE SQL QUERY
$result = mysql_query($sql);
$total = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
$gsref=$row["goldsupplierid"];
$gstitle=$row["goldsuppliername"];
echo"$gsref $gstitle<p>";
echo"<option value='$gsref'>$gstitle</option>";
}
echo" </select>";
}
What I am trying to achieve is to take multiple values from a picklist then using a PHP function to create another picklist based on the results.
So far the code creates an SQL query string successfully and equally successfully passes the variable to the function but that is where it goes wrong. The function recognises the variable (it will display on screen) but will not function as a query. What is puzzling me more is that none of the usual string functions work on it - for example strlen() returns a length of 6. I am obviously missing something but that is the danger of running before you can walk when learning.
function changez(){
var px="select * from `goldsupplier` where goldsupplywhat like '%start%'";
var pl = document.getElementById("goldprods");
var xl= (pl.options.length-1);
for (i = 0; i < (pl.options.length); i++) {
if (pl.options.selected="true"){
wot=pl.options.value;
if (wot=="a"){
px=px+" or goldsupplywhat like '%a%'";
}
if (wot=="b"){
px=px+" or goldsupplywhat like '%b%'";
}
if (wot=="c"){
px=px+" or goldsupplywhat like '%c%'";
}
}
}
document.getElementById("moreinputs").innerHTML = "<?php pickproductsupply('"+px+"'); ?>";
}
the PHP code
function pickproductsupply($prods){
$sql=$prods;
echo $sql;# DISPLAYS THE SQL QUERY
$result = mysql_query($sql);
$total = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
$gsref=$row["goldsupplierid"];
$gstitle=$row["goldsuppliername"];
echo"$gsref $gstitle<p>";
echo"<option value='$gsref'>$gstitle</option>";
}
echo" </select>";
}