我在数据库中有一个名为“收藏夹”的表,其中包含 3 列(user_id、bookmarked_song_id、bookmark_tag),我想获取当前用户的所有 Bookmarked_song_id。
$username = $this->session->userdata('username');
$uidq = mysql_query('SELECT user_id FROM users WHERE username="' . $username . '"');
$rq = mysql_fetch_assoc($uidq);
$user_id = $rq['user_id'];
$getfavq = mysql_query("SELECT * FROM favorites WHERE user_id=$user_id");
$favsr = mysql_fetch_array($getfavq); //contains all the information from the favorites database where user_id is the user_of the currently logged-in user
而且我不知道接下来要使用什么...我想要类似的东西:
foreach($favsr['bookmarked_song_id'] as $song_id) {
$getsongq = mysql_query("SELECT * FROM songs WHERE song_id=$song_id");
$getsongr = mysql_fetch_assoc($getsongq);
$singer = $getsongr['singer'];
$song_name = $getsongr['song_name'];}
显然该方法是错误的,因为我得到:“为 foreach() 提供的参数无效”。谁能帮我找歌?提前致谢。