3

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>
3
  • it is because $payment_id = $row['payment_id']; you never get that value of $payment_id. Commented Jul 3, 2015 at 6:31
  • I have the value in my db in my column payment_id. Commented Jul 3, 2015 at 6:35
  • you are using $row and check where you are getting that $row. you will get my point Commented Jul 3, 2015 at 6:38

1 Answer 1

1

You need to do like below:-

<?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);
        if( $numrows > 0) {
            while($row = mysqli_fetch_assoc($run)){
                $payment_id = $row['payment_id'];
                    if($payment_id == 3){
                        $paid_id = $row['user_id'];
                        $paid_name = $row['firstname'];
                    }else {
                        echo "No Payments made";
                    }
                    if($payment_id == 2){
                        $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){
                         $owes_id = $row['user_id'];
                        $owes_name = $row['firstname'];
                    }else {
                         echo "No one owes";
                    }
            }
        }
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I see what you are saying now. I appreciate your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.