rizzah00 Posted August 8, 2003 Share Posted August 8, 2003 I have two tables in my database -owners -teams in my owners table i have fields for email user_id name and team_id in my teams table i have fields for team_name and team_id I want to do a query that will replace the owners team_id with the teams team_name, i have linked everything correctly, what would the query be? how would i go about displaying this on a page with php? Quote Link to comment https://forums.phpfreaks.com/topic/851-newbie-help/ Share on other sites More sharing options...
pallevillesen Posted August 8, 2003 Share Posted August 8, 2003 select o.user_id, t.team_name from owners u, teams t WHERE o.team_id = t.team_id; Would join the two tables correctly together. If you have entered an owner which have a nonexisting team_id (i.e. the team_id number does not exist in the teams table) - then this owner will NOT be returned... If you want them to come back as well you must do a left join: select o.user_id, t.team_name from owners u LEFT JOIN teams t ON o.team_id = t.team_id; Here all owners will be returned having a team_name of NULL if it is not defined in the teams table... P. Quote Link to comment https://forums.phpfreaks.com/topic/851-newbie-help/#findComment-2833 Share on other sites More sharing options...
rizzah00 Posted August 8, 2003 Author Share Posted August 8, 2003 much thanks, ive left mysql for a year now, trying to get everything to come back Quote Link to comment https://forums.phpfreaks.com/topic/851-newbie-help/#findComment-2839 Share on other sites More sharing options...
rizzah00 Posted August 8, 2003 Author Share Posted August 8, 2003 okay i finally got everything set to where i want it i tweaked some code to try to get another cell from the query and i get this error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/styckx/public_html/maddenworld/owners.php on line 25 Here\'s my code <?php mysql_connect("localhost", "user", "pass"); mysql_select_db("database"); $query = "select o.email, t.name, o.aim, t.location, from owners o, teams t WHERE o.team_id = t.team_id"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ echo "{$row[\'location\']}"; echo "nbsp;"; echo "{$row[\'name\']}"; echo " "; echo "{$row[\'email\']}"; echo " "; echo "{$row[\'aim\']}"; echo "<br>"; } ?> any help would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/851-newbie-help/#findComment-2841 Share on other sites More sharing options...
Barand Posted August 9, 2003 Share Posted August 9, 2003 Remove the comma from between t.location and from. hth Quote Link to comment https://forums.phpfreaks.com/topic/851-newbie-help/#findComment-2859 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.