嗨朋友为什么mysqli在php中用foreach循环拉一行?它不应该获取所有行的数组吗?
$link = new mysqli(DB_SERVER, DB_USER,DB_PASSWORD,DB_NAME) or die('error connecting');
$mob = query("SELECT mobile FROM members_db");
foreach ($mob as $numbers){
$mob_numbers = $numbers['mobile'];
print_r($mob_numbers); exit();
}
答案 0 :(得分:1)
您需要执行以下操作
变化:
foreach ($mob as $numbers)
{
$mob_numbers = $numbers['mobile'];
print_r($mob_numbers); exit();
}
要
$results = array();
foreach ($mob as $numbers)
{
$results[] = $numbers['mobile'];
}
print_r($results); exit();
答案 1 :(得分:1)
您必须逐个“获取”记录
$mob = query("SELECT mobile FROM members_db");
while($row = mysqli_fetch_array($link, $mob)){
print_r($row['mobile'])
}
另外,不确定为什么你在循环中调用exit()。没有意义。
答案 2 :(得分:0)
删除循环中的exit();