我创建了一个表单,要求用户添加:
名字、姓氏、位置、状态
一段时间后我收到了 5 个输入。 mysql表名为users,表数据如下:
id first_name location status
== ========== ======== ========
1 Chris UK Married
2 Anton Spain Single
3 Jacob UK Single
4 Mike Greece Married
5 George UK Married
我也是通过 POST 方法接收输入的方式。所以:
$firstname=$_POST['FIRST_NAME']; // First Name: <input type="text" name="FIRST_NAME">
$location=$_POST['LOCATION']; // Location: <input type="text" name="LOCATION">
$status=$_POST['STATUS']; // Status: <input type="text" name="STATUS">
我创建了一个查询来选择来自英国的所有已婚用户:
$query = "SELECT * FROM users WHERE location='UK' AND status='Married'";
$result = mysqli_query($dbc,$query); //$dbc is the connection to my database
$row = mysqli_fetch_array($results, MYSQLI_BOTH);
换句话说:
id first_name location status
== ========== ======== ========
1 Chris UK Married
5 George UK Married
问题:
1) $row 数组是否如下所示:
$row= array(
array(1 Chris UK Married),
array(5 George UK Married)
);
2)实施过滤后,如何回显数据库的内容 WHERE location='UK' AND status='Married'?
我需要它是这样的:
Hello Chris! You are from UK and you are married!
Hello George! You are from UK and you are married!
我知道我必须使用 foreach 循环(回声数组),但我已经尝试过了,但它不起作用。我尝试过的事情之一是我在 php.net 中找到的东西:
使用 list() 解包嵌套数组
(PHP 5 >= 5.5.0)
PHP 5.5 添加了迭代数组数组的功能,并通过提供 list() 作为值将嵌套数组解包到循环变量中。
例如:
<?php
$array = [
[1, 2],
[3, 4],
];
foreach ($array as list($a, $b)) {
// $a contains the first element of the nested array,
// and $b contains the second element.
echo "A: $a; B: $b\n";
}
?>
当我使用上述内容时,我收到以下错误:
Parse error: syntax error, unexpected T_LIST in C:\wamp\www....
有什么建议么?
据我了解,我必须以某种方式将 ID 与其他数据链接起来。
提前致谢。