Page 1 of 1

Static echo insertion into While Loops?

Posted: Mon Jan 19, 2009 3:12 pm
by cyan studios
I have a while loop that takes some values from our SQL database and it will be echoed into an XFA form to merge to a PDF.

The basic problem is, I need to take some of the results of the row fetch and insert them into one element, then take the rest and insert it into a second element.

I don't want the element tags to repeat like the row results do. I've considered finding ways to turn while results into variables and all kinds of things, and web searches lead me to believe the search itself is erroneous.

Can anyone help me with this?

Code: Select all

if (!$conn)
  {exit('Connection Failed: ' . $conn);}
$sql="SELECT fname, lname, empl FROM PREmployees";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit('Error in SQL');}
  $lname=odbc_result($rs,'lname');
  $fname=odbc_result($rs,'fname');
  $empl=odbc_result($rs,'empl');
$xdpStr = '<valid>';           
echo $xdpStr;
while (odbc_fetch_row($rs))
{       
echo $empl . ',';
}
$xdpStr2 = '</valid>
<valcatch>';
echo $xdpStr2;
 
while (odbc_fetch_row($rs))
{       
echo $fname . ' ' . $lname . ',';
}
 
$xdpStr3 = '</valcatch>';
echo $xdpStr3;
odbc_close($conn);

Re: Static echo insertion into While Loops?

Posted: Mon Jan 19, 2009 6:01 pm
by Burrito
not sure what you mean by 'insert into one element' and 'insert into another element'

you could create two arrays and populate them inside you loop with the values you want. Or alternatively, you could create an object and use the object's property's as the values you're trying to push into 'elements'.