Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generating variables from for loop

Status
Not open for further replies.

GroundZero

Programmer
Feb 1, 2001
28
CA
is there a way I can create variables inside a for loop each time it loop?

here is what I have:

//connect to database
$connect = odbc_connect("$DBname", "", "") or die("couldn't connect.");

$connection=odbc_do($connect);
$num=odbc_num_fields($connection);
for ($i=1,$i<=$num,$i++)
$field($i)=odbc_field_name($connection,$i);


$field would be the variable that need to store value at each loop.I added the $i counter for it to be different everytime. Am I doing this the right way?

thank you in advance,

GroundZero Your soul is imperfect
Life is difficult...

Now guess why we're here
 
$field($i)=odbc_field_name($connection,$i);

To have the variables as $field1, $field2, etc, you need:

$$field$i = odbc...
 
thanks!

but I decided to use array instead!

regards,

GroundZero Your soul is imperfect
Life is difficult...

Now guess why we're here
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top