0

I'm trying to display a HTML table with information from 3 different tables in my mysql DB. However I am unsure on how to display the information from the third table.

Currently what I am using is:

        $SQL = "SELECT members.*, exp.*, lvl.* 
          FROM members 
          INNER JOIN exp ON members.id = exp.member_id
         INNER JOIN lvl ON members.id = lvl.member_id
        ORDER BY lvl.level DESC, 
      lvl.total DESC, xp.total DESC";
        $result = mysql_query($SQL) or die(mysql_error());
        $count = 1;
        while ($row = mysql_fetch_assoc($result)) { 
        $level = $row['level'];
        $exp = $row['exp.overall'];
        }

the $level is from the second table which grabs correctly, and the $exp is what I want to grab from the third table which is "exp" but it doesn't return anything

How can I change this because at the moment it just seems to be focusing on the data from the "lvl" table when using $row[]

Edit: Both the lvl and exp tables have a row in called 'overall' which is why using $row['overall'] doesn't return what I want as it returns the data from lvl table rather than exp.

1
  • share your 3 tables sample data and expected output, without sample its not possible to guide Commented Sep 28, 2018 at 17:41

1 Answer 1

1

First off I believe you have a typo in your last order column: should be exp.total DESC. Secondly, unless you specify the columns to be named with dot notation explicitly they will retain their column names so try changing the last line to: $exp = $row['overall'];.

Also consider using mysqli or PDO.

Sign up to request clarification or add additional context in comments.

2 Comments

$exp = $row['overall']; results in the overall row from the lvl table being returned EDIT: lvl being the second table which also has an 'overall' row. I'm trying to grab the 'overall' row from the exp table
You can simply do this then: $SQL = "SELECT members.*, exp.*, lvl.*, exp.overall AS exp_overall

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.