开发者

Problem with MySQL VALUES using PHP variables

I'm trying to send data from an AJAX call to database tables that are generated from PHP. I'm wr开发者_开发问答apping 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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜