Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/230976-what-am-i-doing-wrong-sql/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.