H
H
hdtor2016-02-15 16:49:11
PHP
hdtor, 2016-02-15 16:49:11

Mystic. Why is it displaying the wrong ID?

$res = $mysqli->query("SELECT n.*, c.id, c.name AS cat_name FROM news AS n LEFT JOIN categories AS c ON n.catid = c.id WHERE n.lang_id = '1'") or sqlerr(__FILE__, __LINE__, $mysqli->error); 
    
while ($row = $res->fetch_array()) {
  echo $row['id'];
}

Should display ID - 1, but displays 2. Why? Some kind of mysticism ...
But if you remove these LEFT_JOIN, it starts working correctly.
Bezymiannyi.png
PS: There are only two entries in the table.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2016-02-15
@VladimirAndreev

"correct" 1 and 2 are n.id or c.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question