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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:50:39+00:00 2026-06-07T22:50:39+00:00

Lets say for example, I have a form, and i post the values to

  • 0

Lets say for example, I have a form, and i post the values to the next page via an array.
I would like to create a while loop that would print out the variables individually.
this is my problem.
I really have an XML document. This XML document I want it to change variables. So I am assuming that implementing the values i pass via an array from the form would need help from some sort of loop so im guessing the while loop will help because i need to stop the loop.

So I have a hotel form. if there are two rooms, I would like to make the while loop stop at two and insert the values from the array form post.
I know how to set up a while loop just need some kind guidance to insert the different values into the xml document.

Here is example:
* There are two rooms i want label 0 and label 1 to go into the child attribute tag, and child 2 and child 3 to go to the 2nd loop within the child attribute tag.

$label[0];
$label[1];
$label[2];
$label[3];
$NumberOfRooms = $_POST['NumbersOfRooms']; 
$count = '0';

while ($count > $NumberOfRooms){ //Assuming that there is two rooms 
$xml = '<checkIn>2012-10-15 </checkIn>
<checkOut>2012-10-18</checkOut>
<numberOfAdults>1</NumberOfAdults>
<numberOfChilderen>2</NumberOfChilderen>
  <ChildAges>
  <childAge age ='."3".' /> $label[0]; 
  <childAge age ='."3".' /> $label[1]
  </ChildAges>';
$count++;
}
  • 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-07T22:50:40+00:00Added an answer on June 7, 2026 at 10:50 pm

    I think this code should do the trick for you.

    <?php
        $label[0];
        $label[1];
        $label[2];
        $label[3];
        $NumberOfRooms = $_POST['NumbersOfRooms']; 
        $xml="";
    
        for($count=0; $count<$NumberOfRooms; $count++)
        {
        $xml .= '<checkIn>2012-10-15 </checkIn>
        <checkOut>2012-10-18</checkOut>
        <numberOfAdults>1</NumberOfAdults>
        <numberOfChilderen>2</NumberOfChilderen>
          <ChildAges>
          <childAge age ='.$label[floor($count*2))].' />  
          <childAge age ='.$label[floor($count*2)+1].' />
          </ChildAges>';
        }
    ?>
    

    The errors that I saw in your code were as follows:

    • Your $count was defined as a string. You were comparing it to a number.
    • Secondly, assuming $count started at zero, how was it ever going to be larger than the number of rooms? I think you got your < and > muddled up.
    • You were overwriting the $xml variable each time you looped through your while statement.
    • Lastly, it is just my opinion, but if you know you only want to loop through a certain number of times, use a for loop over a while – there is less chance of muddling up the logic/drop out conditions.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example. Lets say we have a stackpanel on a form. Its full of
I have 2 websites, lets say - example.com and example1.com example.com has a database
I have a list of items lets say for example a, b, c. As
I have one ArrayList in Session, lets say for example [305,306,380] . On submit,
For example lets say I have a JSON object that contains states and cities.
To use as an example: lets say that I have 2 EditText s and
Lets say, for example, I have a container that takes up 100% of the
So for example ... Lets say I have a Posts model and a News
For example, Lets say that I have a gridview column which has important controls,
Best to use an example to describe the problem. Lets say I have a

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.