【发布时间】:2018-11-18 11:38:57
【问题描述】:
我目前有下面的 PHP 代码,它返回通过$_GET['table'] 传递的表格内容的数组。
$getTable = "SELECT * FROM " .$_GET['table'];
$tableExe = $auth_table->runQuery($getTable);
$tableExe->execute();
$tableArray = $tableExe->fetchAll(PDO::FETCH_ASSOC);
我添加以下内容,它将选择数组中的每个索引以及我想要获取的值:
$lvl1_pos_1 = $tableArray[0]['user_id'];
$lvl1_pos_2 = $tableArray[1]['user_id'];
$lvl1_pos_3 = $tableArray[2]['user_id'];
$lvl1_pos_4 = $tableArray[3]['user_id'];
$lvl1_pos_5 = $tableArray[4]['user_id'];
$lvl1_pos_6 = $tableArray[5]['user_id'];
$lvl1_pos_7 = $tableArray[6]['user_id'];
$lvl1_pos_8 = $tableArray[7]['user_id'];
现在我想找到一种可以轻松收集与每个user_id's 关联的user_name 的方法。 user_name 的结果需要像下面这样输出:
<div><?php echo $lvl1_pos_1; ?><?div>
<div><?php echo $lvl1_pos_2; ?><?div>
<div><?php echo $lvl1_pos_3; ?><?div>
<div><?php echo $lvl1_pos_4; ?><?div>
.....
.....
<div><?php echo $lvl1_pos_8; ?><?div>
关于如何轻松实现这一点的任何建议?
【问题讨论】: