Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL statement updates only one user's data

<?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 the mistake, it was quite stupid:

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

It should be:

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

So, thanks to all! As always: You can't figure it out before you post a question to Stackoverflow :)

like image 261
Algeron Avatar asked Nov 13 '22 11:11

Algeron


1 Answers

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

select s.song_name from rating r
inner join songs s on s.song_name_id = r.song_id
like image 136
aF. Avatar answered Nov 16 '22 04:11

aF.