$ row []中的PHP变量

时间:2018-04-03 13:52:12

标签: php mysqli

知道如何在$ row [] mysqli_query中包含变量吗?

到目前为止我一直在尝试的事情:

1

$result = mysqli_query($connection, "SELECT ".$var." AS Variables, COUNT(*)  FROM data GROUP BY '$var'"); 
while($row = mysqli_fetch_array($result)) {
    echo $row['Variables'];
    echo $row['COUNT(*)']; 
}

2

$result = mysqli_query($connection, "SELECT '$var', COUNT(*)  FROM data GROUP BY '$var'"); 
while($row = mysqli_fetch_array($result)) {
    echo $row[$var];
    echo $row['COUNT(*)']; 
}

另外,我已尝试过所有组合

echo $row[$var];
echo $row["$var"];
echo $row['$var'];

1 个答案:

答案 0 :(得分:2)

试试这个:

$result = mysqli_query($connection, "SELECT ".$var." AS Variables, 
COUNT(*) AS count FROM data GROUP BY '$var'"); 
while($row = mysqli_fetch_array($result)) {
    echo $row['Variables'];
    echo $row['count']; 
}