I am trying to create various, standard HTML list styles from PHP arrays for a movie database I'm building as part of my final year project at university, however I'm having some trouble accessing/understanding how to do this. I've got the relevant data from the various APIs I'm using, but I'd like to create the entire list dynamically, dropping in the correct bits of information where appropriate.

我正在尝试从PHP数组创建各种标准的HTML列表样式,用于我在大学的最后一年项目中构建的电影数据库,但是我在访问/理解如何执行此操作时遇到了一些问题。我从我正在使用的各种API中获取了相关数据,但我想动态创建整个列表,在适当的位置放入正确的信息位。

Details of the two list styles I'm looking to create are below.

我想要创建的两个列表样式的详细信息如下。

List style 1 - Character/Cast details

列表样式1 - 字符/演员详细信息

For the first style of list, I'd like to create it as:

对于第一种列表样式,我想将其创建为:

<ul>
   <li>Cast name - Character name</li>
   <li>Cast name - Character name</li>
   <li>etc. etc.</li>
<ul>

My data set direct from the array looks like this:

直接来自数组的数据集如下所示:

Array
(

[abridged_cast] => Array
    (
        [0] => Array
            (
                [name] => Daniel Craig
                [id] => 162687443
                [characters] => Array
                    (
                        [0] => James Bond
                    )

            )

        [1] => Array
            (
                [name] => Javier Bardem
                [id] => 162661456
                [characters] => Array
                    (
                        [0] => Silva
                    )

            )

        [2] => Array
            (
                [name] => Judi Dench
                [id] => 162652435
                [characters] => Array
                    (
                        [0] => M
                    )

            )

        [3] => Array
            (
                [name] => Ralph Fiennes
                [id] => 162653681
                [characters] => Array
                    (
                        [0] => Gareth Mallory
                        [1] => Mallory
                    )

            )

        [4] => Array
            (
                [name] => Naomie Harris
                [id] => 162705781
                [characters] => Array
                    (
                        [0] => Eve
                    )

            )

    )

In the above example, there's five cast members w/ their respective character names, however on some other examples, there's more or less than five, so, ideally, I'd want the system to know however many cast members were given and create a list for each, up to a maximum of 10 names.

在上面的例子中,有五个演员和他们各自的角色名称,但是在其他一些例子中,有多于或少于五个,所以,理想情况下,我希望系统知道然后给出了很多演员并创建了一个每个列表,最多10个名称。

List style 2 - Videos

列表样式2 - 视频

Similar to the last style, however this list will hopefully look like this:

与上一个样式类似,但是这个列表有望如下所示:

<ul>
    <li><a href='<http://youtube.com/<dynamically generated URL direct to the clip>'><img src='dynamically generated URL to the clip's thumbnail' /></a></li>
    <li>same as above...</li>
</ul>

The source array looks like this:

源数组如下所示:

Array
(
[id] => 37724
[youtube] => Array
    (
        [0] => Array
            (
                [name] => Trailer
                [size] => HQ
                [source] => 24mTIE4D9JM
            )

        [1] => Array
            (
                [name] => Official Trailer
                [size] => HD
                [source] => 6kw1UVovByw
            )

        [2] => Array
            (
                [name] => Trailer 1
                [size] => HD
                [source] => 1Uyjf5Pp0Ko
            )

        [3] => Array
            (
                [name] => Trailer 2
                [size] => HD
                [source] => 5Ejo9_3iUpw
            )

    )

)

Apologies for the length of this post, thanks in advance to anyone who may be able to assist!

对这篇文章的篇幅表示歉意,提前感谢任何可能提供帮助的人!

1 个解决方案

#1


0

The thing you are looking for is called a foreach loop. For your first example it would look something like this:

你正在寻找的东西叫做foreach循环。对于您的第一个示例,它看起来像这样:

foreach($dataSet['abridged_cast'] as $castMember){
    echo '<li>'.$castMember['name'].'-'.implode(', ', $castMember['characters']). '</li>';
}

Now this example is purely illustratory though it most definetely be the begginers approach. Still, I would strongly recommend investigating MVC patterns and PHP frameworks, like for example YII. If deployed and configured right YII with all its goodness should make all the repetitive work done for you here.

现在这个例子纯粹是插图式的,尽管它最明确地是begginers方法。不过,我强烈建议调查MVC模式和PHP框架,例如YII。如果正确部署和配置YII,那么在这里完成所有重复工作。

I've seen that your question contains two parts, though I am not willing to write a sample for the second one, since it is practically the same as the first and with proper attention - you will get on track and figure it out.

我已经看到你的问题包含两部分,虽然我不愿意为第二部分写一个样本,因为它几乎和第一部分一样,并且有适当的关注 - 你会按照正确的方式解决问题。

更多相关文章

  1. 单选按钮和多选按钮的样式设置
  2. 工作中遇到的几个CSS样式表的问题
  3. php 把驼峰样式的字符串转换成下划线样式的字符串
  4. 来自php表单的样式电子邮件
  5. 上传文件时通过AJAX更新列表
  6. 如何用PHP和MYSQL在逗号分隔的列表中找到最流行的10个值
  7. 单击保存按钮(PHP和MSQL)时如何保存记录列表
  8. mysql中select列表可以有group列表中没有的字段,大家不觉得奇怪吗
  9. 使用格式化输出自动扩展Python列表

随机推荐

  1. android listen app package change, con
  2. android学习过程记录2010-12-06
  3. android webService
  4. Android slidingmenu详解 优化侧滑
  5. Java/android下哈希sha1和MD5的实现
  6. Android之Bitmap学习总结
  7. android 去ListView滑动阴影
  8. Android沉浸式状态栏和手机虚拟按钮不兼
  9. Android 布局中 如何使控件居中
  10. Android 沉浸式状态栏实现,以及遇到的问题