SQL statement updates only one user information

<?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>";
    }
    ?>

UPDATE:

Sorry, I found a mistake, it was pretty stupid:

    $catid = $row['rating_id'];
    $catname = $row['song_id'];

It should be:

$catid = $row['song_id'];
$catname = $row['song_name'];

So thank you all! As always: you cannot figure this out before posting a question to Stackoverflow :)

+5
source share
3 answers

For your new question, you can solve it with an inner join:

select s.song_name from rating r
inner join songs s on s.song_name_id = r.song_id
+1
source

Yes,

$ catid = $ row ['rating_id']; // rating identifier is not associated with the song

TO

$ catid = $ row ['song_id']; $ catname = $ row ['song_name'];

0
source

All Articles