将PHP数组传递给Jquery幻灯片

时间:2013-02-14 14:34:43

标签: php jquery

如何从PHP中获取数组并在库函数中填充imagearray?

       $leftimages = $images->GetSlideShowImages($userid,$campaignid,$screenid,'midleft');
       var phparray = <?php echo json_encode($leftimages) ?>;
$.each(phparray, function (i, elem) {
           imagesarray.push(elem['image']); 
});



      var mygallery=new gallery({
wrapperid: "temp1_leftshow_f", //ID of main gallery container,
dimensions: [500, 300], 

    imagearray: [
    ["http://myimageurl1.jpg", "", "_new", "text1"],
    ["http://myimageurl2.jpg", "", "_new", "text2"],
    ["http://myimageurl3.jpg", "", "_new", "text3"],
],

2 个答案:

答案 0 :(得分:1)

在您看到正在形成javascript数组的位置,您可以注入一些PHP来输出值。

例如:

imagearray: [
<?php
    // LOOP AND PRINT
    // e.g. print('["http://myimageurl1.jpg", "", "_new", "text1"],');
?>

答案 1 :(得分:0)

  $leftimages = $images->GetSlideShowImages($userid,$campaignid,$screenid,'midleft');
   var phparray = <?php echo json_encode($leftimages) ?>;
 $.each(phparray, function (i, elem) {
       imagesarray.push(elem['image']); 
     });



  var mygallery=new gallery({
   wrapperid: "temp1_leftshow_f", //ID of main gallery container,
   dimensions: [500, 300], 

imagearray: [
<? for ($i=1;$i++,$i<4){?>
<?php echo $comma; $comma=",";?>["http://myimageurl<?php echo $i;?>.jpg", "", "_new", "text<?php echo $i;?>"]
 <?php }?>
 ],