$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的初学者。
最佳答案
你有你的数组:
$results = array();
你有循环:
while ($rows = $sql -> fetch_assoc()) {
只需将每一行添加到循环内的数组中:
$results = array();
while ($rows = $sql -> fetch_assoc()) {
$results[] = $rows;
}
关于php - 从表中选择记录并存储在多维数组中的面向对象方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45280308/