Retrieving an object error in a union

I have a sql query, for example:

$sql = "SELECT      op.reference_no, op.eight_percent, op.ten_percent, 
                    op.date, op.claim, op.orders_history_id, 
                    oh.one_product_price, oh.quantity


        FROM        order_promotion op

        LEFT JOIN   orders_history oh 
        ON          oh.id = op.orders_history_id

        WHERE       oh.customer_id = $member_id

        UNION ALL       SELECT type, receiveable, null AS a, null AS b, null AS c, 
                        null AS d, null AS e, null AS f 
                        FROM infimoney_transfer

I can echo the data inside the table tag here. <td>".$objek->receiveable."</td>It selects a record from the table.

However, when I tried to check if the entry exists:

$saldo = $mysqli->query($sql);
if(!$saldo){ printf("Errormessage: %s\n", $mysqli->error); die(); }

if ($saldo->num_rows > 0) {
   while($objek = $saldo->fetch_object()) {

    $thq = $objek->receiveable; // line 50
    var_dump($objek->receiveable); // line 51
    echo $objek->receiveable; // line 52
    if ($thq) 
                {
                    $i++;
                    echo "<tr>
                            <td>".$objek->type."</td>
                            <td>".$objek->receiveable."</td> // line 59. 
                            <td>".$i."</td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td>Cinta</td>
                         </tr>";
                }

It arrives with the following error: Undefined property: stdClass::$receiveableon lines 50, 51, 52. While on line 59 it echoes the record without errors.

What is the problem?

+4
source share
1 answer

Try the following:

while($objek = $saldo->fetch_object()) {
    if (isset($objek->receiveable)) 
        {
           $thq = $objek->receiveable; // line 50
           var_dump($objek->receiveable); // line 51
           echo $objek->receiveable; // line 52
           $i++;
           echo "<tr>
                     <td>".$objek->type."</td>
                     <td>".$objek->receiveable."</td> // line 59. 
                     <td>".$i."</td>
                     <td></td>
                     <td></td>
                     <td></td>
                     <td>Cinta</td>
                 </tr>";
         }
0
source

All Articles