I'm really new to php and mysqli and can't understand how to fix this so it returns correctly. Earlyer today I got help to figure out how to use UNION ALL to always return a value. But now the php dosen't wanna work correctly. I've tried but since I don't fully understand this I got no clue how to solve this.
It's supposed to check database for the art_number posted, if the art_number excists it's gonna bind the result from the posted art_number. BUT, if there's no result in database it's supposed to bind results from art_number 111
Very thankful for help!
<?php
include 'dbc.php';
$query = "SELECT
art_price, art_header, art_pic, art_row1, art_row2, art_row3, art_row4
FROM `signs`
WHERE art_number = ?
UNION ALL
SELECT
art_price, art_header, art_pic, art_row1, art_row2, art_row3, art_row4
FROM `signs`
WHERE
art_number = 111
AND NOT EXISTS(
SELECT 1
FROM `signs`
WHERE art_number = ?
)";
if($stmt = $conn->prepare($query)){
$stmt->bind_param('s', $_POST['art_number']);
$stmt->execute();
$stmt->bind_result($rowPrice, $rowHeader, $rowPic, $rowArt1, $rowArt2, $rowArt3, $rowArt4);
while($stmt->fetch()){
?>