Jump to content

What am I doing wrong? SQL..


jeffmorris81

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.