What’s wrong with my statement? I’ve tried everything I can think of.
$stmt = $mysqli->prepare("SELECT host_name, review_title FROM lhr_reviews
UNION
SELECT host_url FROM lhr_hostinfo WHERE host_name = ?
ORDER BY host_name");
$stmt->bind_param("s", $id);
$stmt->execute();
$res = $stmt->get_result();
while($row = $res->fetch_assoc()) {
$list .= "<li><a href='".$row['host_url']."'>".substr($row['review_title'],0,20)."</a></li>";
}
The columns that are selected from the two queries must match each others, in the number of columns and in the corresponding data types:
In your query, the first select selects two columns, where the second one selects only one column. This is not true, you can select empty string in the second select as a work around. The other issue is the
ORDER BY host_nameyou can add it this way, you have to put these queries inside a subquery and order in the outer one like this: