So, I have a database with a few tables in it. Most of these tables contain information about the same document and are connected by an ID (it's stupid since it could all be in the same table, but the company I'm helping out for can't change this right now). The content of the 2 tables that I'm currently working on can be seen below.
tblDocument: Contains ID + other info.
tblVerification: Contains ID, verificationNo + other info.
Now, what I'd like to do is to find the verificationNo in tblVerification from the ID in tblDocument, using PHP and MySQLi. I've found a solution that allows me to pass a variable into the query, but it doesn't feel like this is the most efficient solution and the code confuses me. Any additional information about how the query works or a new simpler solution is greatly appreciated.
<?php
$mysqli = new mysqli("ip", "name", "pw", "db");
$dbDoc = $mysqli->query("SELECT * FROM tblDocument ORDER BY ID");
while ($row = $dbDoc->fetch_assoc()) {
$tempID = $row["ID"];
$bind = 's';
$queryThis = $mysqli->prepare("SELECT verificationNo FROM tblVerification WHERE ID = ?");
$queryThis->bind_param($bind, $tempID);
$queryThis->execute();
$queryThis->bind_result($result);
$queryThis->fetch();
$queryThis->close();
$tempVer = $result;
echo $tempVer . " ";
}
?>
Actual question: Is this the most efficient way to achieve this result using only PHP and MySQLi and/or what can you do to simplify it?