Require in bud



  • Please help me get the JOIN structure straight.

    1. Table spec (all need id, inn, number, product field) введите сюда описание изображения

    2. Table contract. введите сюда описание изображения

    Request structure:

    $sql = "SELECT * FROM spec INNER JOIN contract ON (spec.inn = contract.inn)";
                            $stmt = $dbh->prepare($sql);
                            $stmt->execute();
    
                        $result = $stmt->fetchALL();
                        foreach ($result as $k => $v) {
                            echo "<tr>";
                            echo "<td>" . $v['id'] . "</td>";
                            echo "<td>" . $v['number'] . " от " . $v['date'] . "</td>";
                            echo "<td>" . $v['shortname'] . "</td>";
                            echo "<td>" . $v['product'] . "</td>";
                            echo "<td>" . ' <a href="eidtspec.php?inn=' . $v['inn'] . '">Редактировать</a></td>';
                        }
    

    As a result, I have:
    введите сюда описание изображения

    Problem in column ID, it doesn't match spec.id
    In the future, in order to carry out the editing/detection function, I can only click on the id lines in the spec, all other data can be partly repeated.

    Thank you for your help.



  • This request needs to help you, you choose everything from both tables, so it's not desirable to do-- id tables are confused, and all the other table columns.

    SELECT spec.*,contract.shortname FROM spec INNER JOIN contract ON spec.inn = contract.inn
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2