jeudi 2 juillet 2015

num rows if statement not outputting data from my database

I have a db called payment_status with the following columns:

-id

-user_id

-firstname

-payment_name

-payment_id

-payment_amount

I am trying to structure this so if the payment_id is = to 1 then the table will show all of the users with that id in that table column.

The same applies if a user has a payment_id of 2 or 3, but the 2 would be 'Partially Paid' and 3 would be 'Paid'.

I have users with a payment_id of 1 in my db, but none of the users are being displayed. I am only getting the else statements.

Is anyone able to see what I'm doing wrong to not get any of the users to display?

<?php
//Payment Section

    $con = mysqli_connect("localhost", "root", "", "db");
    $run = mysqli_query($con,"SELECT * FROM payment_status ORDER BY id DESC");
    $numrows = mysqli_num_rows($run);
    $payment_id = $row['payment_id'];

        if($payment_id == 3 AND $numrows > 0) {
                while($row = mysqli_fetch_assoc($run)){
                    $paid_id = $row['user_id'];
                    $paid_name = $row['firstname'];
                }
            } else {
            echo "No Payments made";
        }
        if($payment_id == 2 AND $numrows > 0) {
                    while($row = mysqli_fetch_assoc($run)){
                        $partially_paid_id = $row['user_id'];
                        $partially_paid_name = $row['firstname'];
                        $partially_paid_amount = $row['payment_amount'];
                    }
                } else {
            echo "No Partial Payments made";
        }
        if($payment_id == 1 AND $numrows > 0) {
                    while($row = mysqli_fetch_assoc($run)){
                        $owes_id = $row['user_id'];
                        $owes_name = $row['firstname'];
                    }
            } else {
            echo "No one owes";
        }       
?>

Table

<table class="paymentTable" id="dragTable">
        <tr>
            <th class="thPayment">Paid</th>
            <th class="thPayment">Partially Paid</th>
            <th class="thPayment">Owes</th>
        </tr>
        <tr>
            <td class="tdPayment" id="paid">
                            <div>
            <?php
                if ($paid_name == true) {
                    echo $paid_name;
                } else {
                    echo "No one has paid";
                }
            ?>
                            </div>
            </td>
            <td class="tdPayment" id="partially_paid">
            <div>
            <?php 
                if ($partially_paid__name == true) {
                    echo $partially_paid__name . " - " . $partially_paid_amount;
                } else {
                    echo "No one has made a partial payment";
                }
            ?>  
            </div>
            </td>
            <td class="tdPayment" id="owes">
            <div>
            <?php
                if ($owes_name == true) {
                    echo $owes_name;
                } else {
                    echo "Everyone has paid something";
                }
            ?>  
            </div>
            </td>
        </tr>
    </table>

Aucun commentaire:

Enregistrer un commentaire