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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:41:16+00:00 2026-05-16T18:41:16+00:00

code inside php file: $variable1 = array( ‘variable1’ => $variable1 ); $variable2 = array(

  • 0

code inside php file:

$variable1 = array( 'variable1' => "$variable1" );
      $variable2 = array( 'variable2' => "$variable2" );
            echo json_encode ($variable1);

code inside main page:

<span id="variable1"></span>
<span id="variable2"></span>

I am trying to make it so it echos both variables in their spans.
doing 2 echos does not work, but the single as coded above works

using the jquery form plugin for this.

  • 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-16T18:41:17+00:00Added an answer on May 16, 2026 at 6:41 pm

    If the PHP is fetched w AJAX, then you must create one JSON object with both variables:

    <?php
        // The PHP page
    
        $variable = array( 'variable1' => "$variable1", 
                           'variable2' => "$variable2" );
    
        // One JSON for both variables
        echo json_encode($variable);
    ?>
    

    And then on the main page, you can access the JSON object and display data from it inside your spans. You can do this as I illustrate, but however you do it, if you put the returned JSON in data then you can access the 2 variables with data.variable1 and data.variable2…. like this:

    $.getJSON('yourPath/yourPage.php', function(data) {
    
        // Inside your success callback:
    
        $("#variable1").html(data.variable1);
        $("#variable2").html(data.variable2);
    
    });
    

    Of course, if you’re on the same page, you can use pure PHP:

    <?php
        $variable = array( 'variable1' => "$variable1",
                           'variable2' => "$variable2" );
    ?>
    
    ...
    
    <span id="variable1"><?php echo $variable["variable1"]; ?></span>
    <span id="variable2"><?php echo $variable["variable2"]; ?></span> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make HTML code inside my PHP file and return from
I have this code which will include template.php file from inside each of these
How to insert html code inside an array in PHP? I tried searching on
I have LaTeX code inside PHP (not as .tex file); for example received by
i need to have some php code inside javascript <script ...> <?php echo ...
I am trying out the following code inside a wordpress template: <?php //connect to
I have a chunk of HTML code (with some PHP vars echoed inside of
I have the following jQuery code in my PHP file (edited Jan 19 2010
I've got 800 lines of JS code inside a php script for a site,
currently I have the following code inside my 'function.php' is function calcTime($database_name,$currentTime){ global $startTime;

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.