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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:42:49+00:00 2026-05-14T04:42:49+00:00

On a website I have a number of small PHP scripts to automate changes

  • 0

On a website I have a number of small PHP scripts to automate changes to the text of the site, depending on a figure that’s calculated from a MySQL database. The site is for a fundraising group, and the text in question on the home page gives the total amount raised.

The amount raised is pulled from the database and rounded to the nearest thousand. This is the PHP I use to round the figure and find the last three digits of the total:

$query4 = mysql_query(“SELECT SUM(amountraised) AS full_total FROM fundraisingtotal;”);
$result4 = mysql_fetch_array($query4);
$fulltotal = $result4[“full_total”];
$num = $fulltotal + 30000;
$ftotalr = round($num,-3);
$roundnum = round($num);
$string = $roundnum;
$length = strlen($string);
$characters = 3;
$start = $length – $characters;
$string = substr($string , $start ,$characters);
$figure = $string;

(£30,000 is the amount that had been raised by the previous fundraising team from when the project first started, which is why I’ve added 30000 to $fulltotal for the $num variable)

Currently the text reads:
the bookstall and other fundraising events have raised more than &pound;<? echo number_format($ftotalr); ?>

I’ve just realised though that because the PHP is rounding to the nearest thousand, if the total’s for example £39,200 and it’s rounded to £40,000, to say it’s more than £40,000 is incorrect, and in that case I’d need it to say ‘almost £40,000’ or something similar. I obviously need to replace the ‘more than’ with a variable.

Obviously I need to test whether the last three digits of the total are nearer to 0 or 1000, so that if the total was for example £39,2000, the text would read ‘just over’, if it was between £39,250 and £39,400 something like ‘over’, between £39,400 and £39,700 something like ‘well over’, and between £39,700 and £39,999, ‘almost.’

I’ve managed to get the last three digits of the total as a variable, and I think I need some sort of an if/else/elseif code block (not sure if that would be the right approach, or whether to use case/break), and obviously I’m going to have to check whether the figure meets each of the criteria, but I can’t figure out how to do that. Could anyone suggest what would be the best way to do this please?

  • 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-14T04:42:49+00:00Added an answer on May 14, 2026 at 4:42 am

    Instead of nested if else blocks, you could have a function that takes in the dollar amount and inside the function throw the variable in a switch case statement and at a particular case return the correct echo‘d text.

    Switch cases provide readability over several if else statements. If you need coIde examples, let me know.

    Update:

    Performing comparisons on integers only, switch case is the best bet. When comparing conditions that result in a boolean value, using if else is what you need.

    I had took your code and switched the case to be if else and here is what it looks like with an example output:

    function qualifier($figure) {
            if ($figure < 249) return "just over";
            elseif ($figure < 399) return "over";
            elseif ($figure < 699) return "well over";
            elseif ($figure < 999) return "almost"; 
            else return "No number entered";
         }
         
    echo "We are " . qualifier(250) . " our goal!";
    // outputs: "We are over our goal!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your Repeater is inside an HBox, which has horizontal spacing… May 14, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer Refer to the attribute selectors: =: equals ^: starts with… May 14, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer 32768.5 is not an integer, and it's too big to… May 14, 2026 at 5:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.