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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:22:35+00:00 2026-06-07T15:22:35+00:00

I have a function that display the list of users which is displayUsers() .

  • 0

I have a function that display the list of users which is displayUsers().

Basically instead of having 1 different php file for each page, I have used a switch function to load the content like. This is an example of 1 of the pages.

switch($_GET['page'])  {

   case '#userlist' : $page = '
       <div class="innerbox">
            displayUsers();
       </div> '; break;
}

As you can see it is supposed to show the div tag and load the function, however instead of loading the function, is just displaying the text “displayUsers()”. I understand why it is doing this however I’m not sure how to change it so that is actually runs the function rather that displaying it. Any help would be much appreciated.

Regards

  • 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-06-07T15:22:36+00:00Added an answer on June 7, 2026 at 3:22 pm

    displayUsers() is inside quotes. It’s interpreted as a string. You want

    switch($_GET['page'])  {
    
       case '#userlist': $page = '<div class="innerbox">' . displayUsers() . '</div>'; break;
    
    }
    

    This concatenates the return value of displayUsers() inside the string, assuming displayUsers() returns the code.
    I think you were confusing this feature where variables inside double quoted strings are parsed. This does not work for functions.

    You could also use case '#userlist': $page = sprintf('<div class="innerbox">%s</div>', displayUsers(); break;

    Read about sprintf here: http://php.net/manual/en/function.sprintf.php


    If displayUsers() actually outputs the code itself, then you can use

    switch($_GET['page'])  {
    
       case '#userlist': echo '<div class="innerbox">'; displayUsers(); echo '</div>'; break;
    
    }
    

    What happens is the opening tag is printed, then the function is called (printing the code), then the closing tag is printed, in that order.


    If you’re getting function not defined() then it’s exactly what it sounds like. The function has not been defined in the current script.

    How PHP works
    Each time a page is requested (someone goes to “foo.php”), your server and PHP engine gets the file (foo.php) from some directory, parses it, and (usually) sends something back to the user in the form of an HTML document. Each page is like a “script”, kind of like a mini application that is compiled, executed once, and forgotten.

    So let’s say on your homepage you have displayUsers() defined.

    //index.php
    
    function displayUsers() {
        //some code...
    }
    
    echo "Welcome to my website!", "<br />", 'Click <a href="foo.php">Here</a>.';
    

    When someone goes to your homepage, displayUsers() is defined, yay! However, it’s forgotten right afterwards – the PHP engine has discarded the script after it’s loaded and finished, and certainly does not know what displayUsers() is by the time you reach foo.php.


    So what can you do?
    If you’re only using the function on one page, declare it on that page. Remember, each file is thought of as a script. The PHP engine doesn’t keep track of functions over the user’s session.

    If you’re using the function in multiple scripts, include your functions in some “central” file and include it wherever you need it. I really suggest you read more into PHP and include; I’m not going to explain the basics of PHP; you need to do some more homework.

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

Sidebar

Related Questions

I have a javascript function that toggles the display for rows in a table.
I have one javascript function that used to display the menu and content in
I have a canvas that I am using a javascript function to display text
Inside my Controller i have function that runs after user clicks on item, which
In my Java code I have function that gets file from the client in
I have a function that returns two values in a list. Both values need
I have a page that display of all News in a database, which I
I have a bit of code that checks a list if LI tags which
So I have a JS function that displays a widget at the bottom of
So I have function that formats a date to coerce to given enum DateType{CURRENT,

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.