0

So the code is

$gallery = get_gallery('gallery_id');
print_r ($gallery);

And I get:

Array ( [0] => Array ( [id] => 13 [image] => 0 [user] => 13 [timestamp] => 1366237591 [ext] => png [caption] => Happy smile shi ma? [comment] => ) [1] => Array ( [id] => 14 [image] => 0 [user] => 13 [timestamp] => 1366237954 [ext] => jpg [caption] => Confused [comment] => ) [2] => Array ( [id] => 15 [image] => 0 [user] => 13 [timestamp] => 1366237979 [ext] => jpg [caption] => Facebookerg [comment] => ) [3] => Array ( [id] => 16 [image] => 0 [user] => 13 [timestamp] => 1366377510 [ext] => gif [caption] => lolwut? [comment] => ) [4] => Array ( [id] => 17 [image] => 0 [user] => 13 [timestamp] => 1366380899 [ext] => jpg [caption] => rorwut? [comment] => ) [5] => Array ( [id] => 18 [image] => 0 [user] => 13 [timestamp] => 1366651685 [ext] => jpg [caption] => Notes? [comment] => ) [6] => Array ( [id] => 19 [image] => 0 [user] => 13 [timestamp] => 1366711880 [ext] => jpg [caption] => asd [comment] => ) [7] => Array ( [id] => 20 [image] => 0 [user] => 14 [timestamp] => 1366940983 [ext] => jpg [caption] => Belzelga [comment] => ) )

Which is good, it finally worked. But how do you display a single data/table. Because I am trying to get a single 'id' from these thingies. I tried echoing $gallery['id'] but I got an error. :/

4

5 に答える 5

2

最初に正しいインデックスにアクセスする必要があります。

$gallery[0]['id']
//      ^^^
于 2013-04-27T13:28:52.927 に答える
0

このループ コード セグメントを試してください。

foreach( $gallery as $temp ) {
    echo $temp['id'];
}

あなた$galleryは多次元配列です。それを繰り返す必要があります。

于 2013-04-27T13:28:53.517 に答える
0

特定のギャラリーのみを表示したい場合は、おそらく www.yoursite.com/gallery.php?id=1 のようなものを使用する必要があります。次に、コードで表示します

    if(isset($_GET['id']))
    {
         foreach( $gallery as $g ) 
         {
           if($g['id'] == $_GET['id'])
                 echo $g['id'];
         }
    }
于 2013-04-27T15:27:31.947 に答える