PHP json_encode から JSON オブジェクトを変換またはアクセスできませんでした
<?php
$f_array = array(); // ---- Custom Line 1
for ($i=0; $i < $interval; ++$i)
{
$t_date = date('Y-m-d', strtotime($k_date1 . "+ $i day"));
$f_array = array();
$f_query = mysql_query("select COUNT(j.job_id) as `job_count`
from jobs j
where j.job_posted_date
LIKE '%$t_date%' and j.job_status = 3");
if (mysql_num_rows($f_query) > 0)
{
$f_query_data = mysql_fetch_array($f_query);
$f_count = $f_query_data['job_count'];
$f_array = array_push($f_array, $f_count); // ---- Custom Line 2
// $f_array[] = $f_count; // ---- Custom Line 3
}
}
$j_array = json_encode($f_array);
?>
&1
を使用して、Javascriptで1つの値のみを取得します。enabling
Custom Line 1
Custom Line 2
そして、 iと&enabled
Custom Line 3
を無効にすると。次に、データベースからのように出力が得られますCustom Line 1
Custom Line 2
<script>
var j_array = "<?php echo $j_array; ?>";
</script>
結果1
<script>
var j_array = "1";
</script>
結果2
<script>
var j_array = "["0","0","0","2","0","0","0","0","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","25","0","0","0","0","0","7","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1","0","0","1","1","47","0","1","1","0","0","0","0","0","0","3","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]";
</script>
そして、私は下の画像を添付しました..
次に、または他のメソッドResult 2
の順序でアクセスするにはどうすればよいですか。Array
そして、私は以下を使ってみました
<script>
alert(j_array);
</script>
<script>
alert(j_array.0); // as an Object mightbe .. or I dont have any idea on it, so experimenting ..
</script>
必要なものまたは必要なヘルプ
ないので結果0
が得られinteger
ませんstring
..そして、その場合Array
もトリッキーです..n
いくつかあります..ではString 0
、どうすれば1つずつ呼び出すことができますか。または Javascript 配列に変換します。
注:Result 2
望ましい出力ですが、そうではありませんArray