douzha8489 2012-08-12 21:59
浏览 37
已采纳

动态图像列表使用php mysql smarty里面的jquery

I want to print list of image address in jquery function using php(adodb) and smarty.

i need to this :

 $.lightbox(["/media/photos/tmb/4.jpg", "/media/photos/tmb/3.jpg", "/media/photos/tmb/6.jpg"]);

i try with this (just simple for test) :

 {/literal} {if $photos} $.lightbox(["{"\", \""|implode:$photos}"]); {/if}{literal}

result is :

 $.lightbox(["Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array"]); 

Actually, i need to replace array with images address.

images address (dynamic loop) :

{$relative}/media/photos/tmb/{$photos[i].PID}.jpg

without jquery function, i list images with this methods :

{if $photos}
{section name=i loop=$photos}
{$relative}/media/photos/tmb/{$photos[i].PID}.jpg
{/section}
{/if}

php code:

    $sql            = "SELECT PID, caption FROM photos WHERE AID = " .$aid. " AND status = '1' LIMIT " .$limit;
    $rs             = $conn->execute($sql);
    $photos         = $rs->getrows();
    $smarty->assign('photos', $photos);

how to print list for my need? can i?

  • 写回答

1条回答 默认 最新

  • douhuigang9550 2012-08-12 22:09
    关注

    The easiest thing to do is assign the array to your template, and use json_encode(). I don't use Smarty very often, but I believe you can just do:

    {$yourImageArray | json_encode}
    

    Edit: Now that you've finally told us what your array contains:

    Array ( [0] => Array ( [0] => 13 [PID] => 13 [1] => [caption] => ) [1] => Array ( [0] => 14 [PID] => 14 [1] => [caption] => ) [2] => Array ( [0] => 15 [PID] => 15 [1] => [caption] => ) [3] => Array ( [0] => 30 [PID] => 30 [1] => salam [caption] => salam ) [4] => Array ( [0] => 17 [PID] => 17 [1] => [caption] => ) [5] => Array ( [0] => 31 [PID] => 31 [1] => [caption] => ) [6] => Array ( [0] => 32 [PID] => 32 [1] => [caption] => ) [7] => Array ( [0] => 33 [PID] => 33 [1] => [caption] => ) [8] => Array ( [0] => 34 [PID] => 34 [1] => [caption] => ))

    Here's what you need to do. In your controller:

    $photoFileNames = array();
    foreach ($photos as $photo) {
        $photoFileNames[] = $photo['PID'];
    }
    
    $smarty->assign('photoFileNamesJSON', json_encode($photoFileNames));
    

    In your template, you can access the array via $photoFileNamesJSON. The next time you post a question, please include all of the information from the start. It will be much easier to provide a more specific answer, if you are specific with your question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误