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 5941009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:02:58+00:00 2026-05-22T16:02:58+00:00

As a newbie, my question is is it good practice to write code like

  • 0

As a newbie, my question is is it good practice to write code like this in PHP, mixing HTML and PHP or is there a better way of doing it

<?php 
    if (isset($_POST['submit']))
    {
        $principal_balance = $_POST['principal_amount'];
        $interest_rate = $_POST['interest_rate'];
        $repayment_amount = $_POST['repayment_amount'];

        echo "<html>";
        echo "<head>";
        echo "<title> Loans </title>";
        echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
        echo" <link rel=\"stylesheet\" type=\"text/css\" href=\"styles/document.css\" />";
        echo "<body>";


        echo "<table>";
        echo "<th> Principal Balance </th> <th> Interest Amount </th> <th> Principal Balance Amount Recovered </th> <th> Principal Balance </th> <th> Outstanding Balance </th>";
        while ($principal_balance > 0)
        {

            if ($principal_balance < $repayment_amount)
            {
                exit;
            }
            else
            {
                $interest_amount = $interest_rate * $principal_balance * 1 / 12;

                $principal_amount_recovered = $repayment_amount - $interest_amount;

                $outstanding_balance = $principal_balance - $principal_amount_recovered;

                round ($interest_amount, 2);
                round ($principal_amount_recovered, 2);
                round ($outstanding_balance, 2);
                //echo $principal_balance . "," . $interest_amount . "," . $principal_amount_recovered . "," . $outstanding_balance . "<br />";
                echo "<tr> <td>" . round ($principal_balance, 2) . "</td> <td>" . round ($interest_amount, 2) . "</td> <td>" . round ($principal_amount_recovered, 2). "</td> <td>" . round ($outstanding_balance, 2) . "</td> </td>";

                $principal_balance = $outstanding_balance;          
            }
        }
        echo "</table>";
        echo "</body>";
        echo "</html>";
    }
?>
  • 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-22T16:02:59+00:00Added an answer on May 22, 2026 at 4:02 pm

    Good question.

    I always recommend people who have just started learning PHP that it isn’t very important for them to care about mixing markup and PHP script together, because at the beginning, what you need to learn is to get familiar with the syntax and see how PHP code works.

    But when you improve to a further stage, it’s a GOOD practice to separate markup (HTML) from business layer (PHP script), so that your script looks cleaner, nicer and easier to maintain.

    About you code above, I would recommend you to have a look at this topic, in my reply: How to connect controller to view in PHP OOP?

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

Sidebar

Related Questions

Newbie question: There are three types of Asp.Net controls : HTML server controls, Web
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have a c# newbie question. What is consider good practice out of the
I was wondering if this code is good enough or if there are glaring
Good morning, Apologies for the newbie question. I'm just getting started with ASP.NET internationalization
Newbie question... The objective: I intend to have an HTML text input field as
Total newbie question but this is driving me mad! I'm trying this: myInt =
A question for all the GWT gurus out there. I'm a newbie in GWT
Sorry fot his newbie question. But I really need a start on this one.
This may sound a newbie question, however I'm new to iOS dev. Suppose with

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.