How to first get different related values from diferent SQL tables (PHP)

Posted by Ole Jak on Stack Overflow See other posts from Stack Overflow or by Ole Jak
Published on 2010-03-15T23:44:36Z Indexed on 2010/03/15 23:49 UTC
Read the original article Hit count: 122

Filed under:
|
|
|
|

I am triig to fill options list. I have 2 tables USERS and STREAMS I vant to get all streams and get names of users assigned to that streams.

Users consists of username and id

Streams consists of id, userID, streamID

I try such code:

<?php           
        global $connection;
        $query = "SELECT * 
        FROM streams ";
        $streams_set = mysql_query($query, $connection);
        confirm_query($streams_set);    
    $streams_count = mysql_num_rows($streams_set);
    while ($row = mysql_fetch_array($streams_set)){
            $userid = $row['userID'];
                global $connection;
        $query2 = "SELECT email, username ";
        $query2 .= "FROM users ";
        $query2 .= "WHERE id = '{$userid}' ";

        $qs = mysql_query($query2, $connection);
        confirm_query($qs); 
        $found_user = mysql_fetch_array($qs);


 echo ' <option value="'.$row['streamID'].'">'.$row['userID'].$found_user.'</option> ';
}
    ?>

But it does not return USER names from DB=( So what shall I do to this code to see usernames as "options" text?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql