How do I print out one form????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brookside
Forum Commoner
Posts: 30
Joined: Tue Mar 02, 2004 8:15 pm

How do I print out one form????

Post by brookside »

I am quering a database and buiding a form with the information in the database. For one person in the database they have three addresses. I put mysql_fetch_array in a while loop to make sure I gather all the fields. When I do this, my output is three different forms. All the information is the same on each form except for the address boxes where in each form the address is different. Atleast I know that it is getting the different address but it is putting each address in a seperate form. this is my some of my code.

<?php
if($numRows > 0)
{
while($rows = mysql_fetch_array($result))
{
echo '<form action="" method="post">
<table width="98%" border="0" align="center" cellspacing="2">
.
.
.
.
</table>
</form>';
}
}
?>

I just echoed my whole form to display it.
Please help
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: How do I print out one form????

Post by TheBentinel.com »

If it's ok to use the first address you find, you can put a break at the end of your loop:

Code: Select all

<?php
if($numRows > 0)
{
     while($rows = mysql_fetch_array($result))
    {
         echo '<form action="" method="post">
           <table width="98%" border="0" align="center" cellspacing="2"> 
           .
           .
           .
           .
           </table>
         </form>';
         break; // will terminate after the first record is processed
    }
}
?>
Hope that helps! (And works, I didn't test it, but it looks right)
brookside
Forum Commoner
Posts: 30
Joined: Tue Mar 02, 2004 8:15 pm

Post by brookside »

Thank you Dave....Never thought of a break statement. It worked just fine. :)
Post Reply