json使用turn.js解析为JavaScript数组

时间:2015-10-23 07:33:50

标签: javascript php turnjs

我是新来的,当使用turn.js显示页面翻转时,我的脚本出现问题。 我的页面来自mysql数据库,以json格式存储,然后用JavaScript解析数组,以便通过turn.js查看

这是我的代码:

<body>
<?php
$json_array = Array();

include("setdb.php");
$query="select * from catalogue_page where catalogue_id='5'";    
$result=mysql_query($query);
$totalrec=mysql_num_rows($result);


 while ($hasil=mysql_fetch_array($result)){

    $data=  "images/pages/small/".$hasil['img_file_small'];

 array_push($json_array, $data);  
 }


 $json_array2 = array();

 $query="select * from catalogue_page where catalogue_id='5'";    
 $result=mysql_query($query);

 while ($hasil=mysql_fetch_array($result)){

    $data="images/pages/large/".$hasil['img_file_large'];

    array_push($json_array2, $data);  
  }

?>

<div class="magazine-viewport">
<div class="container">
  <div class="magazine">
  </div>
</div>
</div>

<script type="text/javascript">
var page_image = Array();
var page_image_large = new Array();

page_image = JSON.parse( '<?php echo json_encode($json_array)?>' );

page_image_large = JSON.parse( '<?php echojson_encode($json_array2)?>'   



 );

......
......
 next script from turn.js
</script>

该脚本显示从1列开始的页面,而不是从0列开始

在浏览器中turn.js开始显示来自images / pages / small / 2_5.jpg的页面而不是images / pages / small / 1_5.jpg

我的json解析是

( '["images\/pages\/small\/1_5.jpg","images\/pages\/small\/2_5.jpg","images\/pages\/small\/3_5.jpg","images\/pages\/small\/4_5.jpg","images\/pages\/small\/5_5.jpg","images\/pages\/small\/6_5.jpg"]' ); 

0 coloumn是images\/pages\/small\/1_5.jpg
1 coloumn是images\/pages\/small\/2_5.jpg .... 下一个coloumn

1 个答案:

答案 0 :(得分:0)

最后我是正确的我的脚本和turnjs显示页面的魅力在这里我正确的脚本:

<script type="text/javascript">
var page_image = new Array();
var page_image_large = new Array();

var tampung1 = JSON.parse( '<?php echo json_encode($json_array)?>');
var tampung2 = JSON.parse( '<?php echo json_encode($json_array2)?>');
var j=1;

for(i=0;i<<?php echo $totalrec?>;i++)
{
page_image[j] = tampung1[i];
page_image_large[j] = tampung2[i];
j++
}

 .....
 next turnjs script
</script>

感谢关注。