0

继承我的脚本:http : //ggcc.tv/JSON_Parsers/Music/getcities.php 继承我的 json:http ://www.godsgypsychristianchurch.net/music.json (请同时查看)

问题 1. 它打印出重复,

问:如何让它为每个城市打印一个链接(见 json & script)

  1. 它在网址中添加了一些多余的文本,网址目前看起来像http://www.ggcc.tv/JSON_Parsers/Music/getalbums.php?churchname=Cleveland+OH%3E%3Cbr%20/%3ECleveland%20OH% 3C/a%3E%3Ca%20href=

什么时候应该只是

http://www.ggcc.tv/JSON_Parsers/Music/getalbums.php?churchname=Cleveland+OH

问:我该如何解决这个问题?

请记住 JSON 对同一个城市有多个对象,我只需要列出每个城市一次(而不是多次)

我的PHP:

$churches = array();
    $count = 1;
    foreach ($json['rows'] as $row) {
        ++$count;


{
    if (!in_array($row[doc]['church'], $churches))
        $churches[] = $row[doc]['church'];
}

foreach ($churches as $church)
{
    print '<a href="getalbums.php?churchname=' . urlencode($church) . '><br />' . htmlentities($church) . '</a>'; }


  } 
    exit;

我的 JSON:

{"total_rows":1,"offset":0,"rows":[

              {"id":"All Things Are Possible",
"key":"All Things Are Possible",
"doc":{"_id":"All Things Are Possible",
"album":"All Things Are Possible",
"artwork":"http://godsgypsychristianchurch.net/music_artwork/DEFAULT_COVER2.png",
"baseurl":"http://www.godsgypsychristianchurch.net/music",
"church":"Atlanta GA",
"cityartwork":"http://www.ggcc.tv/LogoNE.png",
"des":"All Things Are Possible from the Atlanta GA Church, Pastor Nick White",
"tracks":[
    {"name":"1 Intro",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/01%20Intro.mp3"},

            {"name":"2 Wo si O Drom",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/02%20Wo%20si%20O%20drom.mp3"},

            {"name":"3 Nas Murrgo Shov",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/03%20Nas%20murrgo%20shov.mp3"},

            {"name":"4 To Cho Vos",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/04%20To%20cho%20vos.mp3"},

            {"name":"5 Tu Son Kai Sastridas",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/05%20Tu%20son%20kai%20sastridas.mp3"},

            {"name":"6 Now I Am Strong",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/06%20Now%20I%20am%20strong.mp3"},

            {"name":"7 Sorr Nevee",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/07%20Zorr%20nevee.mp3"},

            {"name":"8 Preaching",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/08%20Preaching.mp3"},

            {"name":"9 Arkadyan Amey",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/09%20Arkadyan%20amey.mp3"},

            {"name":"10 O Christo Ka Wudarr",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/10%20O%20Christo%20ka%20wudarr.mp3"},

            {"name":"11 Eloi, Eloi",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/11%20Eloi%2C%20Eloi.mp3"},

            {"name":"12 Amadow Dell",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/12%20Amadow%20Dell.mp3"},

            {"name":"13 Sastiar Amey Devla",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/13%20Sastiar%20amey%20Devla.mp3"},

            {"name":"14 Tu Skepeese",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/14%20Tu%20skepeese.mp3"},

            {"name":"15 Dov Ma Godgee",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/15%20Dov%20ma%20godgee.mp3"},

            {"name":"16 The Lord is my strength",
        "url":"/Atlanta%20GA/All%20things%20are%20possible/16%20The%20Lors%20is%20my%20strength.mp3"}
  ]}},



                        {"id":"Can You See Him",
"key":"Can You See Him",
"doc":{"_id":"Can You See Him",
"album":"Can You See Him",
"artwork":"http://godsgypsychristianchurch.net/music_artwork/DEFAULT_COVER2.png",
"baseurl":"http://www.godsgypsychristianchurch.net/music",
"church":"Atlanta GA",
"cityartwork":"http://www.ggcc.tv/LogoNE.png",
"des":"Can You See Him from the Atlanta GA Church, Pastor Nick White",
"tracks":[
    {"name":"1 Aven Luvudes Les",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/01AvenLuvudesLes.mp3"},

            {"name":"2 Aven Onglay",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/02AvenOnglay.mp3"},

            {"name":"3 Chey Bistrov",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/03CheyBistrov.mp3"},

            {"name":"4 Pred Ahmen",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/04PerdAhmen.mp3"},

            {"name":"5 Swento Jeelabas",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/05SwentoJeelabas.mp3"},

            {"name":"6 Pye O Shoovendow",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/06PyeOShoovendo.mp3"},

            {"name":"7 Message",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/07Message.mp3"},

            {"name":"8 Ryah Devla",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/08RyahDevla.mp3"},

            {"name":"9 Hida Bowpahlay",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/09HidaBowpahlay.mp3"},

            {"name":"10 Jeelaben Halleyjah",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/10JeelabenHalleujah.mp3"},

            {"name":"11 Chey Bahro San Devla",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/11CheyBahroSanDevla.mp3"},

            {"name":"12 Woe Sa Kahtey",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/12WoeSaKahtey.mp3"},

            {"name":"13 Noomah Pacha",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/13NoomahPahcha.mp3"},

            {"name":"14 To Worship You I Live",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/14ToWorshipYouILive.mp3"},

            {"name":"15 Regev Mon Devla",
        "url":"/Atlanta%20GA/Can%20You%20See%20Him/15RegevMonDevla.mp3"}

  ]}},


                {"id":"Dey Duma Amensa",
"key":"Dey Duma Amensa",
"doc":{"_id":"Dey Duma Amensa",
"album":"Dey Duma Amensa",
"artwork":"http://godsgypsychristianchurch.net/music_artwork/DEFAULT_COVER2.png",
"baseurl":"http://www.godsgypsychristianchurch.net/music",
"church":"Atlanta GA",
"cityartwork":"http://www.ggcc.tv/LogoNE.png",
"des":"Dey Duma Amensa from the Atlanta GA Church, Pastor Nick White",
"tracks":[
    {"name":"1 Greeting",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/01%20Greeting.mp3"},

            {"name":"2 Godya Vramya",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/02%20Godya%20vramya.mp3"},

            {"name":"3 Vosdoa Vos, Geelabos",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/03%20Vosdoa%20vos%2C%20geelabos.mp3"},

            {"name":"4 Amey Luvudees Tu",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/04%20Amey%20lubudees%20tu.mp3"},

            {"name":"5 Dey Duma Amensa",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/05%20Dey%20duma%20amensa.mp3"},

            {"name":"6 Preaching",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/06%20Preaching.mp3"},

            {"name":"7 I Came to Worship you",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/07%20I%20came%20to%20worship%20you.mp3"},

            {"name":"8 Kon Komel",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/08%20Kon%20Komel.mp3"},

            {"name":"9 Hydee Swento Ducho",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/09%20Hydee%20Swento%20Ducho.mp3"},

            {"name":"10 Mey Luvudeev Tu",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/10%20Mey%20luvudeev%20tu.mp3"},

            {"name":"11 Dov Murrgo Tryo",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/11%20Dov%20murrgo%20tryo.mp3"},

                    {"name":"12 Amey Luvudees tu",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/12%20Amey%20luvudees%20tu.mp3"},

            {"name":"13 Adjes",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/13%20Adjes.mp3"},

            {"name":"14 Wusteelow",
        "url":"/Atlanta%20GA/Dey%20duma%20amensa/14%20Wusteelow.mp3"}
  ]}},



               {"id":"Tuka Jeelabas",
"key":"Tuka Jeelabas",
"doc":{"_id":"Tuka Jeelabas",
"album":"Tuka Jeelabas",
"artwork":"http://godsgypsychristianchurch.net/music_artwork/DEFAULT_COVER2.png",
"baseurl":"http://www.godsgypsychristianchurch.net/music",
"church":"Atlantic City",
"cityartwork":"http://www.ggcc.tv/LogoNE.png",
"des":"Tuka Jeelabas From the Atlantic City Church, Pastor Sam",
"tracks":[

        {"name":"1 Tuka Jeelabas",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/01%20Tuka%20Jeelabas.mp3"},

            {"name":"2 Odel Trodass",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/02%20Odel%20Trodass.mp3"},

            {"name":"3 May Sudov",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/03%20May%20Sudov.mp3"},

            {"name":"4 Moo Si Yetees",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/04%20Moo%20Si%20Yetees.mp3"},

            {"name":"5 Ferrdey Cho Annov",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/05%20Ferrdey%20Cho%20Annov.mp3"},

            {"name":"6 Aven Jeelabas",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/06%20Aven%20Jeelabas.mp3"},

            {"name":"7 Penas Hallelujah",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/07%20Penas%20Hallelujah.mp3"},

            {"name":"8 Falling in Love with Jesus",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/08%20Falling%20in%20Love%20with%20Jesus.mp3"},

            {"name":"9 Lord You Are",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/09%20Lord%20You%20Are.mp3"},

            {"name":"10 Tu Des Pocha",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/10%20Tu%20Des%20Pocha.mp3"},

            {"name":"11 Numma Odel",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/11%20Numma%20Odel.mp3"},

            {"name":"12 Preaching",
        "url":"/Atlantic%20City/Tuka%20Jeelabas/12%20Preaching.mp3"}
  ]}},

        {"id":"Set Free",
"key":"Set Free",
"doc":{"_id":"Set Free",
"album":"Set Free",
"artwork":"http://godsgypsychristianchurch.net/music_artwork/maryland/maryland.jpg",
"baseurl":"http://www.godsgypsychristianchurch.net/music",
"church":"Baltimore MD",
"cityartwork":"http://www.ggcc.tv/LogoNE.png",
"des":"This album is from the Baltimore MD Church, Pastor Nicky",
"tracks":[

        {"name":"1 Set Free",
        "url":"/Maryland/Set_Free/01%20SET%20FREE.mp3"},

            {"name":"2 Chedo Anov",
        "url":"/Maryland/Set_Free/02%20CHEDO%20ANOV.mp3"},

            {"name":"3 Ajujaras",
        "url":"/Maryland/Set_Free/03%20AJUKARAS.mp3"},

            {"name":"4 Pey cho drom",
        "url":"/Maryland/Set_Free/04%20PEY%20CHO%20DROM.mp3"},

            {"name":"5 Rie la Rieango",
        "url":"/Maryland/Set_Free/05%20RIE%20LA%20RIEANGO.mp3"},

            {"name":"6 Asoonen",
        "url":"/Maryland/Set_Free/06%20ASOONEN.mp3"},

            {"name":"7 Aven",
        "url":"/Maryland/Set_Free/07%20AVEN.mp3"},

            {"name":"8 Falling in love with Jesus",
        "url":"/Maryland/Set_Free/08%20FALLING%20IN%20LOVE%20WITH%20JESUS.mp3"},

            {"name":"9 Hallelujah",
        "url":"/Maryland/Set_Free/09%20HALLELUJAH.mp3"},

            {"name":"10 Kie woodod",
        "url":"/Maryland/Set_Free/10%20KIE%20WOODOD.mp3"},

            {"name":"11 Jesus Messiah",
        "url":"/Maryland/Set_Free/11%20JESUS%20MESSIAH.mp3"},

            {"name":"12 Tu Son Swento",
        "url":"/Set_Free/12%20TU%20SON%20SWINTO.mp3"},

            {"name":"13 Mey lulvodeev",
        "url":"/Maryland/Set_Free/13%20MEY%20LUVOODEV.mp3"},

            {"name":"14 Preaching",
        "url":"/Maryland/Set_Free/14%20PREACHING.mp3"}
  ]}},
4

1 回答 1

1

试试这个作为你的 php 代码:

$churches = array();
$count = 1;
foreach ($json['rows'] as $row) {
    ++$count;
    if (!in_array($row[doc]['church'], $churches)){
        $churches[] = $row[doc]['church'];
    }
}
foreach ($churches as $church){
    print '<a href="getalbums.php?churchname=' . urlencode($church) . '><br />' . htmlentities($church) . '</a>'; }
} 
exit;

在打开第二个循环之前,您没有关闭第一个 foreach 循环。您的缩进/大括号结构非常混乱。如果您对此更加勤奋,您会更容易注意到这样的小错误

于 2012-11-13T00:01:48.177 回答