1
$_SESSION_Job101=mysql_fetch_array(mysql_query("SELECT progress FROM job_101 WHERE username='$_SESSION_User'"));
$_SESSION_Job102=mysql_fetch_array(mysql_query("SELECT progress FROM job_102 WHERE username='$_SESSION_User'"));
$_SESSION_Job103=mysql_fetch_array(mysql_query("SELECT progress FROM job_103 WHERE username='$_SESSION_User'"));
$_SESSION_Job104=mysql_fetch_array(mysql_query("SELECT progress FROM job_104 WHERE username='$_SESSION_User'"));
$_SESSION_Job105=mysql_fetch_array(mysql_query("SELECT progress FROM job_105 WHERE username='$_SESSION_User'"));
$_SESSION_Job106=mysql_fetch_array(mysql_query("SELECT progress FROM job_106 WHERE username='$_SESSION_User'"));
$_SESSION_Job107=mysql_fetch_array(mysql_query("SELECT progress FROM job_107 WHERE username='$_SESSION_User'"));
$_SESSION_Job108=mysql_fetch_array(mysql_query("SELECT progress FROM job_108 WHERE username='$_SESSION_User'")); 
$_SESSION_Job109=mysql_fetch_array(mysql_query("SELECT progress FROM job_109 WHERE username='$_SESSION_User'"));
$_SESSION_Job1010=mysql_fetch_array(mysql_query("SELECT progress FROM job_110 WHERE username='$_SESSION_User'"));

for ($x=1;$x<=10;$x++)
{
$e = '$_SESSION_Job10'.$x;
//if ($e >= 100)
//{ $_SESSION_Job10.$x.['progress'] = 100; }
echo $e;
}

我可以让 $e 变量返回我想要的变量,但是我希望 $e 在我的 if 语句中基本上充当该变量,而不仅仅是返回它的名称。当我从 if 语句中删除注释时,我的页面变为空白而不是回显 $e。我该如何做到这一点?

4

1 回答 1

0

用这个

$e = ${'_SESSION_Job10'.$x}; // $e = $_SESSION_Job101; actual variable here

现场演示

代替

$e = '$_SESSION_Job10'.$x;   // $e = '$_SESSION_Job101'; // string here

编辑

你必须像这样使用数组

${'_SESSION_Job10'.$x}['progress'];

演示

于 2013-06-19T05:24:49.597 回答