php - Using multiple tables inner join on one key item. Can't figure out what is wrong

961

For the life of me I can not figure out where I have went wrong I am pulling the data from these multiple tables but no data appearing

$result=mysql_query("SELECT * FROM chars uc
INNER JOIN zone_settings t ON uc.pos_zone = t.zoneid    
INNER JOIN char_look v ON uc.charid = v.charid  
INNER JOIN char_jobs y ON uc.charid = y.charid  
INNER JOIN char_stats n ON uc.charid = n.charid     
INNER JOIN char_profile p ON uc.charid = p.charid 
WHERE `accid`='".$user["id"]."' ORDER BY `charid`");

Thanks kwolfe using LEFT JOIN and Removing the ORDER BY it works now. Here is the code.

$result=mysql_query("SELECT * FROM chars uc
LEFT JOIN zone_settings t ON uc.pos_zone = t.zoneid     
LEFT JOIN char_look v ON uc.charid = v.charid   
LEFT JOIN char_jobs y ON uc.charid = y.charid   
LEFT JOIN char_stats n ON uc.charid = n.charid  
LEFT JOIN char_profile p ON uc.charid = p.charid 
WHERE `accid`='".$user["id"]."'");
625

Answer

Solution:

Switch to LEFT JOINS to see if your missing a relationship along the way (INNER JOIN will only show data where a relationship is made for each table, in this case ALL tables.)

People are also looking for solutions to the problem: mysql - PHP foreign keys issues - I can't update a database field with a foreign key

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.