Link to home
Start Free TrialLog in
Avatar of jmarx75
jmarx75

asked on

defining variables inside a counter

I am trying to define variables inside a counter for later use. Check this out:
 $i = 0;
while($candidatelist = mysql_fetch_array($candidates))
{
$i++;
$candidateid = $candidatelist['id'];
} 

Open in new window

$candidates comes from a database. The $candidatelist array returns 2 results.
What i want to do is add the counter variable to the $candidateid variable so I can separate them out for later use.
Like I would like $candidateid1, $candidateid2 etc for use in an ajax function. For the life of me I can't get it to work.
I tried things like.
$candidateid.$i =  $candidateid.$i;

Open in new window

and
$candidateid + $i;

Open in new window

But those doesn't seem to work. This seems like a simple thing to do, but i just can't get it to work.
Can anyone help?
 
ASKER CERTIFIED SOLUTION
Avatar of nplib
nplib
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try

eval("\$candidateid".$i." = \"".$candidatelist['id']."\";");
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial