jeffmorris81 Posted March 18, 2011 Share Posted March 18, 2011 this is a table in my website.. called 'user' useridusername myuseridmyusername and this is the phpbb table... called 'phpbb_users' in the same database user_iduser_activeusername phpbbmyuserid1zugzwangle The usernames in the phpbb database are the same as those on my main website. I want to find the link the data to the usernames.. so for example... usernameuser_iduserid zugzwanglephpbbmyuseridmyuserid the code i have so far is: include "includes/start.php"; //contains db info etc... // establish database connection $link = mysql_connect ($h, $u, $p) or die ("Could not connect to database, try again later"); // is working.. mysql_select_db($d,$link); $query = ("SELECT phpbb_users.user_id, phpbb_users.username, user.userid, user.username FROM phpbb_users LEFT JOIN user ON phpbb_users.username=user.username ORDER BY user_id"); $forumandsite = mysql_query($query) or die('Query failed: ' . mysql_error()); echo print_r(mysql_fetch_array($forumandsite)); // does nothing... while($forumdivision = mysql_fetch_array($forumandsite, MYSQL_ASSOC)) { echo $forumdivision[0]; // this outputs nothing either... } //echo count($forumancldivision).'<br>'; echo $forumdivision['username']; // does nothing ?> Where are I going wrong?? I can't see how to access the data, and I am certain both tables are populated by a lot of data.. Please help if you can. Zugz Quote Link to comment https://forums.phpfreaks.com/topic/230976-what-am-i-doing-wrong-sql/ Share on other sites More sharing options...
Pikachu2000 Posted March 18, 2011 Share Posted March 18, 2011 Does the query return any results if you paste it into phpMyAdmin (or Navicat, or whatever you use)? Quote Link to comment https://forums.phpfreaks.com/topic/230976-what-am-i-doing-wrong-sql/#findComment-1189002 Share on other sites More sharing options...
jeffmorris81 Posted March 18, 2011 Author Share Posted March 18, 2011 Yes, it works in a phpbb admin query.. therefore the query is correct but the permissions are wrong? Quote Link to comment https://forums.phpfreaks.com/topic/230976-what-am-i-doing-wrong-sql/#findComment-1189013 Share on other sites More sharing options...
Pikachu2000 Posted March 18, 2011 Share Posted March 18, 2011 You're selecting fields with the same name from different tables, which is likely causing some ambiguity. I believe you'll need to alias the fields. Regarding this: "echo $forumdivision[0]; // this outputs nothing either..." I wouldn't expect it to output anything. You've specified MYSQL_ASSOC in the fetch, so an enumerated indes won't exist. You should really be developing with error reporting on at its highest level. You would have probably gotten some warnings regarding undefined indexes. Quote Link to comment https://forums.phpfreaks.com/topic/230976-what-am-i-doing-wrong-sql/#findComment-1189176 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.