0

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()){
        ?>
  • This Q isn't answered before, getting error wouldn't help me since I don't understand half of it. That's why I asked for help. – Petrus Alli Jun 15 '16 at 20:04
  • Getting the error and showing it here might help *someone else* understand what is happening in your code. Please capture the errors reported and edit your question to include the results. You can click the `edit` link below the question (directly above these comments) to include the additional information in your question. – Michael Gaskill Jun 15 '16 at 21:22

0 Answers0