$select = SELECT * FROM `registration_form`;
$sql = $conn -> query($select);
if ($sql->num_rows > 0) {
$results = array();
while ($rows = $sql -> fetch_assoc()) {
$rows = $rows['userName'];
$password = $rows['password'];
$name = $rows['name'];
$address = $rows['address'];
$country = $rows['country'];
$zipCode = $rows['zipCode'];
$email = $rows['email'];
$sex = $rows['sex'];
$language = $rows['language'];
$about = $rows['about'];
}
} else {
return false;
}
这是正常的PHP编码。但是我想知道如何改变面向对象的方式并以多维方式存储变量?我是PHP的初学者。
答案 0 :(得分:0)
你有你的阵列:
$results = array();
你有你的循环:
while ($rows = $sql -> fetch_assoc()) {
只需将每一行添加到循环内的数组中:
$results = array();
while ($rows = $sql -> fetch_assoc()) {
$results[] = $rows;
}