<?php
function get_user_id($username) {
return mysql_result(mysql_query("Select id From users Where username = '" . mysql_real_escape_string($username) . "'"), 0);
}
$sql = "select * from rating
WHERE user_id=" . get_user_id($myusername) . "
ORDER BY punkte ASC";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
$catid = $row['rating_id'];
$catname = $row['song_id'];
echo "<li id='item_$catid' class='ui-state-default'><span class='ui-icon ui-icon-arrowthick-2-n-s'></span>$catname</li>";
}
?>
更新
抱歉,我发现了这个错误,非常愚蠢:
$catid = $row['rating_id'];
$catname = $row['song_id'];
应该是:
$catid = $row['song_id'];
$catname = $row['song_name'];
所以,谢谢大家!一如既往:在向Stackoverflow发布问题之前,你无法弄明白:)
答案 0 :(得分:1)
对于您的新问题,您可以使用内部联接来解决它:
select s.song_name from rating r
inner join songs s on s.song_name_id = r.song_id
答案 1 :(得分:0)
答案 2 :(得分:0)
是,
$ catid = $ row ['rating_id']; //评级ID与歌曲无关
要
$ catid = $ row ['song_id']; $ catname = $ row ['song_name'];