0

I'm trying to send data from an AJAX call to database tables that are generated from PHP. I'm wrapping the MySQL queries in a function with for loops so I can create any number of tables on the fly. I have every part of it working except for the query that defines the VAULES. I'm trying to append an integer variable at the end of $usrscore so that as it loops through, my VALUES will be $usrscore1, $usrscore2, $usrscore3, etc. The problem is that it only picks up the integer as the value (i.e. 1, 2, 3) instead of using the entire variable (i.e. $usrscore1, $usrscore2, $usrscore3).

Concatenating doesn't work (i.e. "$usrscore" . $counter . ") and combining them as two separate variables doesn't work either (i.e. $usrscore + $counter). If I literally write out the variable with an integer at the end it works as expected but I need this to work in a loop.

Thanks!

1
  • 1
    Post the code, and the error message Commented Apr 2, 2011 at 19:51

1 Answer 1

1

as i guess you want to call a variable, but don't know it's name. you must concatenate them like:

$myvar1 = 'hi there';
$str = 'myvar';
$int = 1;
echo ${$str.$int};

it must return

hi there

hope it helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.