What's new

Anu po kaya kulang o mali sa php ko

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
pano ko kaya palalabasin lahat ng data ko.. kasi kapag nilog in ko na sya as user may lumalabas naman na output/data kaso isang data lang gusto ko sana lahat ng data ni ganito ay lalabas.. at yun huli kong input o update ko ay sya ang nasa unahan..

ito po code ko

sample.php

<?php


session_start();

include "../config/config.php";

if(isset($_SESSION['id'])){

$user_id = $_SESSION['id'];

$_GET_RECORD = mysqli_query($con,"SELECT * FROM login WHERE id = '$user_id' ");

while($row_edit = mysqli_fetch_assoc($_GET_RECORD)) {

$payee_name = $row_edit['payee_name'];
$email_address = $row_edit['email_address'];
$phone = $row_edit['phone'];
$birthday = $row_edit['birthday'];
$username = $row_edit['username'];
$password = $row_edit['password'];

}

}else {
echo "You must login first! <a href = '../login.php'>Login now! </a>";
}


$slq = "SELECT login.payee_name, payment.particular, payment.amount, payment.lddap_ada, payment.date FROM login INNER JOIN payment ON login.payee_name = payment.payee_name WHERE login.username = '$username' AND login.password = '$password' ";

$result = $con->query($slq);
if($result -> num_rows > 0) {
while ($row = $result->fetch_assoc()) {

$payee_name = $row["payee_name"];
$particular = $row["particular"] ;
$amount = $row["amount"];
$lddap_ada = $row["lddap_ada"] ;
$date = $row["date"];
}
} else {
echo "No results found.";
}

// I-close ang connection
$con->close();

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel = "stylesheet" href ="../css/bootstrap.css">
<script src="../js/bootstrap.bundle.js"></script>
</head>
<body>
<div class="container mt-3">
<h2>Striped Rows</h2>
<p>The .table-striped class adds zebra-stripes to a table:</p>
<table class="table table-striped">
<thead>
<tr>
<th>Payee Name</th>
<th>Particular</th>
<th>Amount</th>
<th>LDDAP ADA</th>
<th>Date</th>
<th>Status</th>

</tr>
</thead>
<tbody>
<td><?php echo $payee_name; ?></td>
<td><?php echo $particular; ?></td>
<td><?php echo $amount; ?></td>
<td><?php echo $lddap_ada; ?></td>
<td><?php echo $date; ?></td>
<td><?php ?></td>
</tr>
</tbody>
</table>
</div>





</body>
</html>
 
To display all the data from your query, you need to move the table rows inside the while loop. Here's how you can modify your code:

Code:
<?php 

session_start();

include "../config/config.php";

if(isset($_SESSION['id'])){

    $user_id = $_SESSION['id'];

    $_GET_RECORD = mysqli_query($con,"SELECT * FROM login WHERE id = '$user_id' ");

    while($row_edit = mysqli_fetch_assoc($_GET_RECORD)) {
        $payee_name = $row_edit['payee_name'];
        $email_address = $row_edit['email_address'];
        $phone = $row_edit['phone'];
        $birthday = $row_edit['birthday'];
        $username = $row_edit['username'];
        $password = $row_edit['password'];
    } 
} else {
    echo "You must login first! <a href = '../login.php'>Login now! </a>";
}

$sql = "SELECT login.payee_name, payment.particular, payment.amount, payment.lddap_ada, payment.date FROM login INNER JOIN payment ON login.payee_name = payment.payee_name WHERE login.username =  '$username' AND login.password = '$password' ";

$result = $con->query($sql);

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/bootstrap.css">
    <script src="../js/bootstrap.bundle.js"></script>
</head>
<body>
    <div class="container mt-3">
        <h2>Striped Rows</h2>
        <p>The .table-striped class adds zebra-stripes to a table:</p>            
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>Payee Name</th>
                    <th>Particular</th>
                    <th>Amount</th>
                    <th>LDDAP ADA</th>
                    <th>Date</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if($result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()) {
                        $payee_name =  $row["payee_name"];
                        $particular = $row["particular"];
                        $amount = $row["amount"]; 
                        $lddap_ada = $row["lddap_ada"];
                        $date = $row["date"];
                        ?>
                        <tr>
                            <td><?php echo $payee_name; ?></td>
                            <td><?php echo $particular; ?></td>
                            <td><?php echo $amount; ?></td>
                            <td><?php echo $lddap_ada; ?></td>
                            <td><?php echo $date; ?></td>
                            <td><?php // Add your logic for status here ?></td>
                        </tr>
                        <?php
                    }
                } else {
                    echo "<tr><td colspan='6'>No results found.</td></tr>";
                }
                ?>
            </tbody>
        </table>
    </div>
</body>
</html>

<?php 
// Close the connection
$con->close();
?>

This code will iterate through each row of data returned by your query and display them in the table. If there are no results, it will display a "No results found" message. You can add your logic for the status column inside the loop.
 
To display all the data from your query, you need to move the table rows inside the while loop. Here's how you can modify your code:

Code:
<?php

session_start();

include "../config/config.php";

if(isset($_SESSION['id'])){

    $user_id = $_SESSION['id'];

    $_GET_RECORD = mysqli_query($con,"SELECT * FROM login WHERE id = '$user_id' ");

    while($row_edit = mysqli_fetch_assoc($_GET_RECORD)) {
        $payee_name = $row_edit['payee_name'];
        $email_address = $row_edit['email_address'];
        $phone = $row_edit['phone'];
        $birthday = $row_edit['birthday'];
        $username = $row_edit['username'];
        $password = $row_edit['password'];
    }
} else {
    echo "You must login first! <a href = '../login.php'>Login now! </a>";
}

$sql = "SELECT login.payee_name, payment.particular, payment.amount, payment.lddap_ada, payment.date FROM login INNER JOIN payment ON login.payee_name = payment.payee_name WHERE login.username =  '$username' AND login.password = '$password' ";

$result = $con->query($sql);

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/bootstrap.css">
    <script src="../js/bootstrap.bundle.js"></script>
</head>
<body>
    <div class="container mt-3">
        <h2>Striped Rows</h2>
        <p>The .table-striped class adds zebra-stripes to a table:</p>           
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>Payee Name</th>
                    <th>Particular</th>
                    <th>Amount</th>
                    <th>LDDAP ADA</th>
                    <th>Date</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if($result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()) {
                        $payee_name =  $row["payee_name"];
                        $particular = $row["particular"];
                        $amount = $row["amount"];
                        $lddap_ada = $row["lddap_ada"];
                        $date = $row["date"];
                        ?>
                        <tr>
                            <td><?php echo $payee_name; ?></td>
                            <td><?php echo $particular; ?></td>
                            <td><?php echo $amount; ?></td>
                            <td><?php echo $lddap_ada; ?></td>
                            <td><?php echo $date; ?></td>
                            <td><?php // Add your logic for status here ?></td>
                        </tr>
                        <?php
                    }
                } else {
                    echo "<tr><td colspan='6'>No results found.</td></tr>";
                }
                ?>
            </tbody>
        </table>
    </div>
</body>
</html>

<?php
// Close the connection
$con->close();
?>

This code will iterate through each row of data returned by your query and display them in the table. If there are no results, it will display a "No results found" message. You can add your logic for the status column inside the loop.
maraming salamat po ask ko lang po pano sya iaarrange na kung alin po yun huling update ko sya ang nasa unahan po parang po bang yun huling input ko ay sya naman yun makikita first and so on sa output.
 
maraming salamat po ask ko lang po pano sya iaarrange na kung alin po yun huling update ko sya ang nasa unahan po parang po bang yun huling input ko ay sya naman yun makikita first and so on sa output.
To display the data in reverse order, you can modify your SQL query to include an ORDER BY clause with the date column in descending order. Here's an updated version of your code:

PHP:
<?php

session_start();

include "../config/config.php";

if(isset($_SESSION['id'])){

    $user_id = $_SESSION['id'];

    $_GET_RECORD = mysqli_query($con,"SELECT * FROM login WHERE id = '$user_id' ");

    while($row_edit = mysqli_fetch_assoc($_GET_RECORD)) {
        $payee_name = $row_edit['payee_name'];
        $email_address = $row_edit['email_address'];
        $phone = $row_edit['phone'];
        $birthday = $row_edit['birthday'];
        $username = $row_edit['username'];
        $password = $row_edit['password'];
    }
} else {
    echo "You must login first! <a href = '../login.php'>Login now! </a>";
}

$sql = "SELECT login.payee_name, payment.particular, payment.amount, payment.lddap_ada, payment.date FROM login INNER JOIN payment ON login.payee_name = payment.payee_name WHERE login.username =  '$username' AND login.password = '$password' ORDER BY payment.date DESC";

$result = $con->query($sql);

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/bootstrap.css">
    <script src="../js/bootstrap.bundle.js"></script>
</head>
<body>
    <div class="container mt-3">
        <h2>Striped Rows</h2>
        <p>The .table-striped class adds zebra-stripes to a table:</p>           
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>Payee Name</th>
                    <th>Particular</th>
                    <th>Amount</th>
                    <th>LDDAP ADA</th>
                    <th>Date</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if($result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()) {
                        $payee_name =  $row["payee_name"];
                        $particular = $row["particular"];
                        $amount = $row["amount"];
                        $lddap_ada = $row["lddap_ada"];
                        $date = $row["date"];
                        ?>
                        <tr>
                            <td><?php echo $payee_name; ?></td>
                            <td><?php echo $particular; ?></td>
                            <td><?php echo $amount; ?></td>
                            <td><?php echo $lddap_ada; ?></td>
                            <td><?php echo $date; ?></td>
                            <td><?php // Add your logic for status here ?></td>
                        </tr>
                        <?php
                    }
                } else {
                    echo "<tr><td colspan='6'>No results found.</td></tr>";
                }
                ?>
            </tbody>
        </table>
    </div>
</body>
</html>

<?php
// Close the connection
$con->close();
?>

I added the ORDER BY payment.date DESC clause to the query, which will order the results by the date column in descending order. This will display the latest input first.
 
To display the data in reverse order, you can modify your SQL query to include an ORDER BY clause with the date column in descending order. Here's an updated version of your code:

PHP:
<?php

session_start();

include "../config/config.php";

if(isset($_SESSION['id'])){

    $user_id = $_SESSION['id'];

    $_GET_RECORD = mysqli_query($con,"SELECT * FROM login WHERE id = '$user_id' ");

    while($row_edit = mysqli_fetch_assoc($_GET_RECORD)) {
        $payee_name = $row_edit['payee_name'];
        $email_address = $row_edit['email_address'];
        $phone = $row_edit['phone'];
        $birthday = $row_edit['birthday'];
        $username = $row_edit['username'];
        $password = $row_edit['password'];
    }
} else {
    echo "You must login first! <a href = '../login.php'>Login now! </a>";
}

$sql = "SELECT login.payee_name, payment.particular, payment.amount, payment.lddap_ada, payment.date FROM login INNER JOIN payment ON login.payee_name = payment.payee_name WHERE login.username =  '$username' AND login.password = '$password' ORDER BY payment.date DESC";

$result = $con->query($sql);

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/bootstrap.css">
    <script src="../js/bootstrap.bundle.js"></script>
</head>
<body>
    <div class="container mt-3">
        <h2>Striped Rows</h2>
        <p>The .table-striped class adds zebra-stripes to a table:</p>          
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>Payee Name</th>
                    <th>Particular</th>
                    <th>Amount</th>
                    <th>LDDAP ADA</th>
                    <th>Date</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if($result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()) {
                        $payee_name =  $row["payee_name"];
                        $particular = $row["particular"];
                        $amount = $row["amount"];
                        $lddap_ada = $row["lddap_ada"];
                        $date = $row["date"];
                        ?>
                        <tr>
                            <td><?php echo $payee_name; ?></td>
                            <td><?php echo $particular; ?></td>
                            <td><?php echo $amount; ?></td>
                            <td><?php echo $lddap_ada; ?></td>
                            <td><?php echo $date; ?></td>
                            <td><?php // Add your logic for status here ?></td>
                        </tr>
                        <?php
                    }
                } else {
                    echo "<tr><td colspan='6'>No results found.</td></tr>";
                }
                ?>
            </tbody>
        </table>
    </div>
</body>
</html>

<?php
// Close the connection
$con->close();
?>

I added the ORDER BY payment.date DESC clause to the query, which will order the results by the date column in descending order. This will display the latest input first.
maraming salamat po....
 

Similar threads

Back
Top