0

I am using left join query in my php script. The code which i am using is

$tot = "SELECT
                        c.id,
                        c.name AS companyname,
                        m.companyid,
                        m.name AS naam
                        FROM
                        org c
                        LEFT JOIN login m ON c.id = m.companyid
                    ";
        $query = $con->query($tot);

        $total = $query->num_rows;

it is giving this error to me "Notice: Trying to get property of non-object in on line $total = $query->num_rows;
"

But when i am using this line of code it is giving total num of rows easily to me. The code i am using is

$tot = "SELECT * FROM org GROUP BY id ORDER BY dateadded DESC";
        $query = $con->query($tot);

        $total = $query->num_rows;

        echo $total;

it is working absolutely fine. SO what is the wrong thing i am doing in above code.

Upendra Sharma
  • 575
  • 2
  • 9
  • 28
  • 2
    You have a comma before the `FROM`. I vote to close these as simple typographical errors. And, you should look at the error from the *database*, not simply the fact that the query did not run. – Gordon Linoff Dec 04 '16 at 13:34
  • I have removed comma but still it is giving same error. So don't close this. – Upendra Sharma Dec 04 '16 at 13:36
  • Run the query directly in the MySQL's console and see what you're getting. – Rajdeep Paul Dec 04 '16 at 13:39
  • actually if i am passing single argument from other table then it is working fine but not for multiple column names. Like it is working for single m.companyid but not for m.companyid, m.name – Upendra Sharma Dec 04 '16 at 14:00

0 Answers0