此代码有效:
$i=1;
require('db.php');
$query = "SELECT own".$i." FROM users WHERE username='".$_SESSION['username']."'";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
所以我试着将它放入循环中,但它不起作用。我只获得了第一个结果。 甚至可以这样做吗?
while (isset($row['own'.$i])) {
require('db.php');
$query = "SELECT own".$i." FROM users WHERE username='".$_SESSION['username']."'";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
echo $row['own'.$i];
$i++;
}
我也使用上面的代码在循环之前进行第一次检查
答案 0 :(得分:0)
您始终只选择SELECT own1
。
您需要foreach
而不是while
require('db.php');
$query = "SELECT * FROM users WHERE username='".$_SESSION['username']."'"; // SQL Injection HERE!
$result = mysqli_query($con, $query);
$rows = mysqli_fetch_assoc($result);
foreach ($rows as $row)) {
var_dump($row);
}