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

  • Home
  • SEARCH
  • 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 7011921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:11:19+00:00 2026-05-27T22:11:19+00:00

I have a chunk of PHP code that I’d like to include on a

  • 0

I have a chunk of PHP code that I’d like to include on a number of different pages but be able to update in one location (hence my use of an include file). However, the chunk of code needs to appear inside a while loop — specifically inside a while loop that is echoing out MySQL rows.

However, there are roughly 200 rows in the MySQL query I’m echoing, so having an include in the loop really slows things down. I’ve tried making what’s in the include file a function, like shown below, then including once at the top of the page and referencing the function inside the loop, but it it doesn’t seem to work (I just don’t get any data in the variables I’m setting, etc.)

How does one put a chunk of code inside a loop without using include?

Thanks very much.

function CYCalc()
{


  // If the company's current fiscal quarter
  // is equal to the current calendar quarter,
  // use the company's fiscal years as calendar years

  if ($UniverseResult[CurQ] == "Q1" && $UniverseResult[CurYear] == "2012") {
    $C2011Sales =  number_format($UniverseResult[SalesYear2]/1000000,1); 
    $C2012Sales =  number_format($UniverseResult[SalesYear3]/1000000,1);
    $C2011EPS =  $UniverseResult[EPSYear2]; 
    $C2012EPS =  $UniverseResult[EPSYear3];
  }
}
  • 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-27T22:11:20+00:00Added an answer on May 27, 2026 at 10:11 pm

    Remember PHP’s scoping rules. Variables defined in the global scope are not visible inside functions unless you explicitly declare them as global within the function:

    <?php
    
    $x = 7;
    
    function y() {
       echo $x; // undefined
    }
    
    function z() {
       global $x;
       echo $x; // 7
    }
    
    function a($x) {
       echo $x; // 7
    }
    

    For your CYCalc() to work, you’d need to declare $UniverseResult global as per z() above, or pass it in as a parameter as per a() above.

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

Sidebar

Related Questions

I've found out that my web pages (mainly index.php, main.html, include.inc) have been injected
I have a large chunk of legacy php code that I need to interface
I have written a chunk of code that is aimed at reordering pages. <form
I have a chunk of code where it appears that a variable is changing
If I have a chunk of code like this: .hover( function () { hoverState($(#navbar
I have a chunk of code that defines div s and some of the
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
Is there a tool that works like Resharper for C# but for HTML/PHP for
I have a chunk of javascript that users can copy and paste to put
Imagine I have a chunk of initialisation code at the top of a stored

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.