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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:52:07+00:00 2026-05-21T06:52:07+00:00

In order to generate a XML i am using following Code currently. .<?php require

  • 0

In order to generate a XML i am using following Code currently.

   .<?php

    require ('../dbconfig/dbconfig.php');

    $appId = $_GET['id'];

    $sqlTabs = "Select _id,tab_title,position from tab_info where app_id=$appId order by position ";
    $resultTabs=mysql_query($sqlTabs );
    $countTabs=mysql_num_rows($resultTabs);

    if($countTabs>0)
    {
        echo '<application applicationName="sample app">';
        echo '<tabs>';
        while ($rowTab = mysql_fetch_array($resultTabs) ) {


            echo '<tab id="t'.$rowTab['_id'].'" tabtitle="'.$rowTab['tab_title'].'" position="'.$rowTab['position'].'" data="somedata">';

            $sqlTabItems =  "Select _id as tabitemId,item_type,item_title,item_data from items_info where tab_id=".$rowTab['_id']." and parent_id=0 order by _id ";
            $resultTabItems=mysql_query($sqlTabItems);
            $countTabItems=mysql_num_rows($resultTabItems);
            if($countTabItems>0)
            {
               $level = 1; 
               echo '<listItems>';
                while ($rowTabItem = mysql_fetch_array($resultTabItems) ) {

                        echo '<listItem id="'.$rowTabItem['tabitemId'].'" parentId="t'.$rowTab['_id'].'" itemtype="'.$rowTabItem['item_type'].'" itemtitle="'.$rowTabItem['item_title'].'" itemdata="'.$rowTabItem['item_data'].'" level="'.$level.'">';

                             giveitems($rowTabItem['tabitemId'],$rowTab['_id'],$level);

                        echo '</listItem>';
                }
                echo '</listItems>';

            }
            else
               echo 'No Data';
            echo '</tab>';
        }
        echo '</tabs></application>';
    }
    else
    {
        echo 'No Data';//  no tabs found
    }

function giveitems($pitemId,$tabId,$level)
{

$sqlItems = "Select _id,item_type,item_title,item_data from items_info where parent_id=".$pitemId." order by _id ";

$resultItems=mysql_query($sqlItems);

$countItems=mysql_num_rows($resultItems);

$numbers = 0;

 if($countItems>0)
{
 $level = $level +1;
 echo '<listItems>';

while ($rowItem = mysql_fetch_array($resultItems) ) {

echo '<listItem  id="'.$rowItem[0].'" parentId="'.$pitemId.'" itemtype="'.$rowItem[1].'" itemtitle="'.$rowItem[2].'" itemdata="'.$rowItem[3].'" level="'.$level.'">';


/*********** Recursive Logic ************/
 if(giveitems($rowItem[0],$tabId,$level)==1)
 {
      echo '</listItem></listItems>';
           return 1;
  }    
else 
 {
   echo '</listItem></listItems>';
   return -1;
  }                   
 }         
        } 
        else
        {
                echo 'No Data';//  no tabs found
                return -1;
        }        
}

?>

Now in this code i want to replace all echo statements with a String variable and then i want to write that String variable content into a file , the porblem is if i define the string variable at the top of the file even then also that string variable cannot accessible from the giveItems functions below.

Pls suggest some solution

  • 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-21T06:52:08+00:00Added an answer on May 21, 2026 at 6:52 am

    To access a global variable from within a function you need to write global $varname; at the top of that function’s definition. Example:

    function giveitems($pitemId,$tabId,$level) {
        global $xmlstring;
        // ....
    }
    

    However, this is pretty bad practice nowadays and you’d be better off writing a class that will both produce the XML and write it to a file.

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

Sidebar

Related Questions

I'm trying to generate a unique ID in php in order to store user-uploaded
Iam trying to generate the menu and For that iam using navigation.xml (Zend Framework)
I need to generate a list of activity from multiple tables in order of
In my application I am loading xml from url in order to parse it.
I am trying to generate an xml file of a recipe database that has
I have the following XML, which is generated by a 3rd-party library: <PhoneNumbers> <PhoneNumber
I'm using Hibernate/JPA and have an @Entity object called Order, pointing at a MySQL
I'm writing a simple program to help generate orders for a game I'm a
In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary
In order to perform a case-sensitive search/replace on a table in a SQL Server

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.