请问如何把PHP中查询的信息在javascrip中转换为数组//在php文件中,从数据库中找到一类产品的所有颜色:
$StyleNo = $_REQUEST['productid'];
$select = 'SELECT p.colorid, c.colorname';
$from = ' FROM productinfo AS p, color AS c';
$where = ' WHERE p.productid = \'' . $StyleNo . '\' and c.colorid = p.colorid';
$queryResult = @mysql_query($select . $from . $where);
// 输出选到的所有颜色,
while ($row = mysql_fetch_array($queryResult)) {
print_r ($row);
} //结果是:
Array( [0] => 04 [colorid] => 04 [1] => 04-Blue [colorname] => 04-Blue)
Array( [0] => 06 [colorid] => 06 [1] => 06-Taupe [colorname] => 06-Taupe)
Array( [0] => 05 [colorid] => 05 [1] => 05-Black [colorname] => 05-Black) //在javascript 中:
function updateColor(index) {
if (request.readyState == 4) {
if (request.status == 200) {
/* Get the response from the server */
var productcolor = new Array(request.responseText); // 我需要的结果:
// var productcolor = new Array(["04","04-blue"],["06", "06-taupe"],["05","05-black"]);
/* Update the HTML web form */
for(var i = 0; i < productcolor.length; i++){
var getvalue = productcolor[i][0];
var getData = productcolor[i][1];
document.getElementById("Colour"+index).options.add(new Option(getData,getvalue));
}
}
}
}
//asker:www.yuanshi88.com请问如何转换,多谢!!
--------------------------------------------------------------------------------
$StyleNo = $_REQUEST['productid'];
$select = 'SELECT p.colorid, c.colorname';
$from = ' FROM productinfo AS p, color AS c';
$where = ' WHERE p.productid = \'' . $StyleNo . '\' and c.colorid = p.colorid';
$queryResult = @mysql_query($select . $from . $where);
// 输出选到的所有颜色,
while ($row = mysql_fetch_array($queryResult)) {
print_r ($row);
} //结果是:
Array( [0] => 04 [colorid] => 04 [1] => 04-Blue [colorname] => 04-Blue)
Array( [0] => 06 [colorid] => 06 [1] => 06-Taupe [colorname] => 06-Taupe)
Array( [0] => 05 [colorid] => 05 [1] => 05-Black [colorname] => 05-Black) //在javascript 中:
function updateColor(index) {
if (request.readyState == 4) {
if (request.status == 200) {
/* Get the response from the server */
var productcolor = new Array(request.responseText); // 我需要的结果:
// var productcolor = new Array(["04","04-blue"],["06", "06-taupe"],["05","05-black"]);
/* Update the HTML web form */
for(var i = 0; i < productcolor.length; i++){
var getvalue = productcolor[i][0];
var getData = productcolor[i][1];
document.getElementById("Colour"+index).options.add(new Option(getData,getvalue));
}
}
}
}
//asker:www.yuanshi88.com请问如何转换,多谢!!
--------------------------------------------------------------------------------
json_encode一下