This should be bone simple, and as usual, I'm probably overlooking something due to my less-than-thorough way of teaching myself code. Hopefully this makes sense...
In a php loop, I have this:
var key = <?php echo json_encode($key); ?>;
var id<?php echo $key;?> = <?php echo json_encode($value['Claim']['id']); ?>;
var point<?php echo $key;?> = <?php echo json_encode($value['Claim']['point']); ?>;
Which evaluates just as I want it. So id2 equals whatever id2 is supposed to be, etc.
Then later I need to call those variables, like this:
var takeurl = '/api/response.json?point='+ point + '&id=' + id;
Except I want "point" and "id" to be the value of "point2" or "point4" or, in shorthand, point+key.
If I write it as
var takeurl = '/api/response.json?point='+ point + key + '&id=' + id;
it returns the value of "point" plus the value of "key," not the value of point2 or point3.
Then I realise that at the very beginning, when declaring those values, I shouldn't have to hit php all the time. I should be able to do something like:
var key = <?php echo json_encode($key); ?>;
var id[key] = <?php echo json_encode($value['Claim']['id']); ?>;
var point{"key"} = <?php echo json_encode($value['Claim']['point']); ?>;
And then create the new variable using the same convention. I've read similar questions where the answer involves using arrays, but again, this is all in a larger php loop, so I don't see that fitting the situation here.
Sorry, I hope this was clear. I'm earning my username on this one. Ideas?
EDITED TO ADD: The problem is a little different than what I've explained above. My code is apparently pulling the values of the final variables that appear in the loop (as if I weren't defining them by a 'key' distinction at all, but just defining "point" five times). I fear I'm not making sense at all. Here's some code so you can see what's going on: codepad.org/ETX5dI6C
What I need is, for example, when clicking the fourth link on the page, for the values for id4 and point4 to be pulled. Instead, no matter what link I click, it passes the variables for id5 and point5, which were defined last. I don't get it?
var takeurl = '/api/response.json?point='+ point.toString() + key.toString() + '&id=' + id;orvar takeurl = '/api/response.json?point='+ point + '' + key + '&id=' + id;@