User 2 offers to buy an item from User 1. User 1 can accept or reject. If User 1 accepts, then they will both be able to offer feedback about the transaction.
I have 2 blocks of IF statements. They both work and do the same thing but which is better coding practice?
IF BLOCK 1 checks if which user is there first and then checks if the transaction was accepted or if its still pending
if ($_SESSION['user_id'] == $seller) {
if ($row['status'] == 'P') {
echo '<p>' . get_username_by_id($row['buyer']) . ' has made a bid of ' . $row['price'] . ' for your ' . $row['title'] . '
<a href="transactions.php?id=' . $transactionid . '&action=accept">Accept</a> / <a href="transactions.php?id=' . $transactionid . '&action=reject">Reject</a><br />';
} else if ($row['status'] == 'A') {
echo '<p>' . get_username_by_id($row['buyer']) . ' paid ' . $row['price'] . ' for your ' . $row['title'] . '</p>';
echo '<a href="feedback.php?id=' . $transactionid . '&action=givefeedback">Give Feedback</a></p>';
}
} else if ($_SESSION['user_id'] == $buyer) {
if ($row['status'] == 'P') {
echo '<p> You have made a bid of ' . $row['price'] . ' for ' . $row['title'] . '</p>';
} else if ($row['status'] == 'A') {
echo '<p> You have paid ' . $row['price'] . ' for ' . $row['title'] . '</p>';
echo '<a href="feedback.php?id=' . $transactionid . '&action=givefeedback">Give Feedback</a></p>';
}
}
Or
IF BLOCK 2 has only 4 if statements and checks both user and status of transaction at same time
if ($_SESSION['user_id'] == $seller && $row['status'] == 'P') {
echo '<p>' . get_username_by_id($row['buyer']) . ' has made a bid of ' . $row['price'] . ' for your ' . $row['title'] . '
<a href="transactions.php?id=' . $transactionid . '&action=accept">Accept</a> / <a href="transactions.php?id=' . $transactionid . '&action=reject">Reject</a><br />';
} else if ($_SESSION['user_id'] == $buyer && $row['status'] == 'P') {
echo '<p> You have made a bid of ' . $row['price'] . ' for ' . $row['title'] . '</p>';
} else if ($_SESSION['user_id'] == $seller && $row['status'] == 'A') {
echo '<p>' . get_username_by_id($row['buyer']) . ' paid ' . $row['price'] . ' for your ' . $row['title'] . '</p>';
echo '<a href="feedback.php?id=' . $transactionid . '&action=givefeedback">Give Feedback</a></p>';
} else if ($_SESSION['user_id'] == $buyer && $row['status'] == 'A') {
echo '<p> You have paid ' . $row['price'] . ' for ' . $row['title'] . '</p>';
echo '<a href="feedback.php?id=' . $transactionid . '&action=givefeedback">Give Feedback</a></p>';
}