Require in bud
-
Please help me get the JOIN structure straight.
Table spec (all need id, inn, number, product field)
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