I am having some difficulty executing multiple queries.
I have been reading about mysqli_multi_query however I'm not sure how to implement this into my existing code.
Ideally I need to query two separate tables and display the results within the same while loop. Should this be a do-while, or am I way off?
My current code is;
$id = $_GET['id'];
//setup first query
$query = ("SELECT pub_id, title FROM vw_ft_search WHERE pub_id = $id");
//setup second query
$query = ("SELECT phys_desc FROM vw_physical_descriptions WHERE publication_id = $id");
$result = $conn->query($query);
if($result === false) {
trigger_error('Wrong SQL: ' . $query . ' Error: ' . $conn->error, E_USER_ERROR);
}
while($row = $result->fetch_assoc()){
//result from first query
if (!empty($row['pub_id'])){ echo $row['pub_id'] . '<br />'; }
else echo "no information" .'<br />';
//result from first query
if (!empty($row['title'])){ echo $row['title'] . '<br />'; }
else echo "no information" .'<br />';
//result from second query here
}
New to this so any help/advice is appreciated.
JOIN. OrUNIONmysqliyou should be using parameterized queries andbind_paramto add user data to your query. DO NOT use string interpolation or concatenation to accomplish this because you will create severe SQL injection bugs. NEVER put$_GETdata directly into a query.