gpt4 book ai didi

php - cakephp2.1 中的数据获取问题

转载 作者:行者123 更新时间:2023-11-29 14:25:31 25 4
gpt4 key购买 nike

我有简单的播放列表数据库结构......它采用这种格式

sr.no |    album_id |    song_id |    artist_id |    user_id
<小时/>
1.    |    160      |    85      |    40        |    5
2. | 160 | 85 | 45 | 5
3. | 160 | 85 | 41 | 6
4. | 160 | 85 | 44 | 5

意味着album_id、song_id 和artist_id 的组合使完整的记录独一无二。我想使用 CAKEPHP 条件获取组中的记录。例如。我想要这种格式的数据。假设我想在特定部分显示它,例如。

album_id | song_id | artist_id
160 | 85 | 40, 45, 41, 44

我的试用代码是这个..

        $playlist_condition = array('Tracklist.album_id' => $album_id, 'OR'=> array('Tracklist.status'=> 1, 'Tracklist.user_id'=>$user_id));
$trackdetails = $this->Tracklist->find('all', array('conditions' => $playlist_condition ));
$this->set("trackdetails", $trackdetails);

注意递归地我也想找到相关的模型..

我当前的输出是..

Array
(
[0] => Array
(
[Tracklist] => Array
(
[id] => 140
[album_id] => 1
[song_id] => 185
[artist_id] => 33
[video_link] =>
[status] => 1
[user_id] =>
[created] => 2012-05-25 10:08:50
[modified_by] =>
[modified] => 2012-05-25 10:08:50
)

[Album] => Array
(
[id] => 1
[name] => Om, Namah Shivay
[photo] =>
[genre] => Devotional
[copyrights] =>
[year] => 0000
[source] =>
[description] => Its' an devotional Album.
[download_link] =>
[status] => 2
[user_id] => 1
[created] => 2012-04-06 00:00:00
[modified_by] => 0
[modified] => 2012-04-22 09:11:35
)

[Song] => Array
(
[id] => 185
[name] => Shad.aab
[hindi] => अ
[roman] => a
[category] => Qawwalli
[poet_id] => 148
[status] => 7
[user_id] => 1
[created] =>
[modified_by] =>
[modified] => 2012-04-22 09:07:48
)

[Artist] => Array
(
[id] => 33
[name] => Suresh Vadekar
[photo] =>
[description] => Suresh Vadekar.
[status] => 1
[user_id] => 1
[created] => 2012-05-20 18:12:38
[modified_by] =>
[modified] => 2012-05-20 18:12:39
)

)

[1] => Array
(
[Tracklist] => Array
(
[id] => 138
[album_id] => 1
[song_id] => 185
[artist_id] => 31
[video_link] =>
[status] => 1
[user_id] =>
[created] => 2012-05-25 10:04:55
[modified_by] =>
[modified] => 2012-05-25 10:04:55
)

[Album] => Array
(
[id] => 1
[name] => Om, Namah Shivay
[photo] =>
[genre] => Devotional
[copyrights] =>
[year] => 0000
[source] =>
[description] => Its' an devotional Album.
[download_link] =>
[status] => 2
[user_id] => 1
[created] => 2012-04-06 00:00:00
[modified_by] => 0
[modified] => 2012-04-22 09:11:35
)

[Song] => Array
(
[id] => 185
[name] => Shad.aab
[hindi] => अ
[roman] => a
[category] => Qawwalli
[poet_id] => 148
[status] => 7
[user_id] => 1
[created] =>
[modified_by] =>
[modified] => 2012-04-22 09:07:48
)

[Artist] => Array
(
[id] => 31
[name] => Mehdi Hassan
[photo] =>
[description] => Mehdi Hassan Sahaab one of the prominiet singer of Asia...
[status] => 1
[user_id] => 1
[created] => 2012-05-20 18:07:20
[modified_by] =>
[modified] => 2012-05-20 18:07:20
)

)

[2] => Array
(
[Tracklist] => Array
(
[id] => 139
[album_id] => 1
[song_id] => 185
[artist_id] => 32
[video_link] =>
[status] => 1
[user_id] =>
[created] => 2012-05-25 10:04:55
[modified_by] =>
[modified] => 2012-05-25 10:04:55
)

[Album] => Array
(
[id] => 1
[name] => Om, Namah Shivay
[photo] =>
[genre] => Devotional
[copyrights] =>
[year] => 0000
[source] =>
[description] => Its' an devotional Album.
[download_link] =>
[status] => 2
[user_id] => 1
[created] => 2012-04-06 00:00:00
[modified_by] => 0
[modified] => 2012-04-22 09:11:35
)

[Song] => Array
(
[id] => 185
[name] => Shad.aab
[hindi] => अ
[roman] => a
[category] => Qawwalli
[poet_id] => 148
[status] => 7
[user_id] => 1
[created] =>
[modified_by] =>
[modified] => 2012-04-22 09:07:48
)

[Artist] => Array
(
[id] => 32
[name] => Jagjit Singh
[photo] =>
[description] => Jagjit Singh Sahab my favorite Sahab.
[status] => 1
[user_id] => 1
[created] => 2012-05-20 18:11:07
[modified_by] =>
[modified] => 2012-05-20 18:11:07
)

)

)

最佳答案

在 MySQL 中使用 GROUP_CONCAT 怎么样?

SELECT album_id, artist_id, GROUP_CONCAT(song_id) FROM my_table GROUP BY album_id, artist_id

关于php - cakephp2.1 中的数据获取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11056753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com