我有两个表,table2nameColumn
包含 table1 列的名称,例如
表格1
id|check|status|...|
1 |abc |1 |...|
表2
|nameColumn|...|
|check |...|
|status |...|
我想在 table1 中获取值,列名是 table2 中的值
$sql="SELECT * FROM `table1` WHERE `id` = 1 ";
$result = mysqli_query($conn,$sql) or die (mysql_error ());
$rowTable = mysqli_fetch_array($result);
$s = "SELECT * FROM table2";
$r = mysqli_query($conn,$s);
while($row1 = mysqli_fetch_array($r)){
$columnName = $row1['nameColumn'];
$value = $rowTable["'".$columnName."'"]; // fail why?
//$value = $rowTable['check']; // working?
}
我不知道为什么$value = $rowTable["'".$columnName."'"];
会像这样的错误失败
Notice: Undefined index: 'check' ...
但是如果我直接使用$value = $rowTable['check']; // working why?
怎么解决 谢谢