This code loops through a mysql table and prints out empty/null fields. It however prints the array values and the keys like this
此代码循环遍历mysql表并打印出空/空字段。然而,它打印数组值和这样的键
Array (
[0] => Field "dob" on entry "1" is empty/null
[1] => Field "user_name" on entry "7" is empty/null
)
How do I print something like this field "dob" on entry "1" is empty/null
如何在条目“1”上打印此字段“dob”之类的内容为空/空
$sql = "SELECT * FROM userinfo";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
foreach($row as $key => $field) {
if(empty($field)) {
$emptyFields[] = sprintf('Field "%s" on entry "%d" is empty/null', $key, $row['userid']);
}
}
}
print_r($emptyFields);
4 个解决方案
#1
9
echo implode('<br>', $emptyFields);
#2
1
That is because you are using print_r to output that array. So the output is formatted readable for humans. To make it more pretty try to iterate through it like you did before with that field:
那是因为您使用print_r输出该数组。因此输出格式化对人类可读。为了使它更漂亮,尝试像之前使用该字段一样迭代它:
foreach($emptyFields as $key => $field) {
echo('Field "'.$field.'" on entry "'.$emptyField['userid'].'" is empty/null');
}
#3
0
$sql = "SELECT * FROM userinfo";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
foreach($row as $key => $field) {
if(empty($field)) {
$emptyFields[] = sprintf('Field "%s" on entry "%d" is empty/null', $key, $row['userid']);
}
}
}
#4
0
i dont know if I get this correctly but I think the solution to your problem is:
我不知道我是否正确,但我认为你的问题的解决方案是:
change the last line to:
将最后一行更改为:
$emptyFields[] = sprintf('Field "%s" on entry "%d" is empty/null', $field, $row['userid']);}}}print_r($emptyFields);
#1
9
echo implode('<br>', $emptyFields);
#2
1
That is because you are using print_r to output that array. So the output is formatted readable for humans. To make it more pretty try to iterate through it like you did before with that field:
那是因为您使用print_r输出该数组。因此输出格式化对人类可读。为了使它更漂亮,尝试像之前使用该字段一样迭代它:
foreach($emptyFields as $key => $field) {
echo('Field "'.$field.'" on entry "'.$emptyField['userid'].'" is empty/null');
}
#3
0
$sql = "SELECT * FROM userinfo";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
foreach($row as $key => $field) {
if(empty($field)) {
$emptyFields[] = sprintf('Field "%s" on entry "%d" is empty/null', $key, $row['userid']);
}
}
}
#4
0
i dont know if I get this correctly but I think the solution to your problem is:
我不知道我是否正确,但我认为你的问题的解决方案是:
change the last line to:
将最后一行更改为:
$emptyFields[] = sprintf('Field "%s" on entry "%d" is empty/null', $field, $row['userid']);}}}print_r($emptyFields);