Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1000777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:34:00+00:00 2026-05-16T07:34:00+00:00

User 2 offers to buy an item from User 1 . User 1 can

  • 0

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>';
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:34:00+00:00Added an answer on May 16, 2026 at 7:34 am

    The first one shows you the path: if the statuses were to increase in number, you could abstract the functionality into a function with little work. It looks and is cleaner.

    I’d also prefer to separate the actual HTML from PHP. Instead of

    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 />';
    

    I’d prefer

    <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>
    </p>
    

    But to each his own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement a facility like Orkut offers where user is able
I have a site that offers a keyword search. The user can perform a
The Yahoo User Interface library offers rollup support if you use their CDN. I'm
I'm working on an iPhone app that offers the user the opportunity to send
I am trying to develop a functionality and I need to offer user a
I'd like to offer a user of my app the ability to highlight or
I want to offer the user a list of urls that he/she has clicked
I have a long text and I'd like to offer the user a reading
I am developing an application and I'd like to offer the user a possibility
When a user registers with my site I want to offer them a login

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.