0

i have a little question here... i have a PHP array like this..

Array
(
    [0] => Array
        (
            [idCustomer] => 2553
            [session] => 
            [noMobil] => 666
            [keterangan] => Sistem
            [tahun] => 2012
            [merk] => Sistem
        )

    [1] => Array
        (
            [idCustomer] => 2553
            [session] => 
            [noMobil] => 7777
            [keterangan] => hahahaha
            [tahun] => 2120
            [merk] => 
        )

)

And i stored that array to **$_SESSION[datamobil]**.. and then my question is.. how to populate that array into selectbox using jquery.. so the select box is like this..

<select id='mobil' name='mobil'>
<option> - PILIH MOBIL - </option>
<option value='666'>666</option>
<option value='7777'>7777</option>
</select>

and when i select one of that selectbox option.. it will populate the detail element... like this

selectbox : [-- 666 --] <-- the selectbox
- Detail -
keterangan : Sistem
tahun : 2012
merk : Sistem

any one can help me?? thanks before

EDIT :

a code to get the array..

$query = "SELECT * FROM customer_car WHERE idCustomer = '$_SESSION[idCustomer]'";
        $go = $db->query($query);
        $mobil_array = array();
        while($car = $go->fetchAll(PDO::FETCH_ASSOC))
        {
            $mobil_array = $car;
        }
        $_SESSION[datamobil] = $mobil_array;
4

1 回答 1

0

您是否使用jquery ajax..来获取该数组?如果是.. 考虑将整个数组分配给一个变量arrayvariable ,因此在 jquery 端,您可以将代码指定为

var replacetext="<option value=''> - PILIH MOBIL - </option>";
for(var i=0; i<arrayvariable.length;i++)
{
 replacetext+="<option value='"+arrayvariable[i]+"'>"+arrayvariable['i']['noMobil']+"</option>";
}
$('#mobil').html(replacetext);

您可以使用 jquery更改事件。显示特定手机的详细信息..

编辑

在您的情况下,如果变量存储在 session.get 变量并在 php 中执行相同的 for 循环

$sesionvariable=$_SESSION[datamobil];
echo "<select id='mobil' name='mobil'><option> - PILIH MOBIL - </option>";
for ($i=0;$i<=count($sesionvariable);$i++)
{
echo "<option value='".$sesionvariable[$i]."'>".$sesionvariable[$i]['noMobil']."</option>";
}
echo "</select>";

并为该选择框使用 onload更改事件。

希望这可以帮助..

于 2012-12-10T05:49:29.670 回答