Ok so I have an array "$landing" in my header.php, then in my page.php I include the header.php but for some reason when I call the 'Name' field in the array in the page.php: echo $landing['Name'];
it just doesn't work.
好了,我的标题中有一个数组“$landing”。php,然后在我的页面。php我包括标题。但是由于某种原因,当我在页面中的数组中调用“Name”字段时。php:echo $着陆(“名字”);它只是不工作。
this is how the array is being filled up, and calling it in the header works perfectly.
这就是填充数组的方式,并且在头中调用它可以很好地工作。
$landing = array();
while ($row = mysql_fetch_array($result)) {
$str = strtolower($row['Name']);
if ($str == $name) {
$landing = $row;
}
}
To clarify, $row and $landing are both arrays, and both have multiple fields 'Name' 'Color' 'Info'.
需要说明的是,$row和$landing都是数组,并且都有多个字段“Name”“Color”“Info”。
What am I doing wrong here? Do I need to make it global somehow or what's going on?
我在这里做错了什么?我需要使它全球化吗?
3 个解决方案
#1
3
The original code works somehow, now as the OP said in a comment.
正如OP在评论中所说,原始代码以某种方式工作。
But my old tips still hold:
但我的老建议仍然站得住脚:
- Consider using MySQLi or PDO instead of the deprecated MySQL extension!
- 考虑使用MySQLi或PDO,而不是废弃的MySQL扩展!
- Why do you compare the dataset's column value on the client-side? You can do this on the MySQL side, it'll be faster!
- 为什么要比较客户端上数据集的列值?你可以在MySQL这边做,它会更快!
#2
0
You are, as ComFreek correctly stated, turning $landing into a string. Instead, if you're trying to add an entry to the landing array, use [] brackets which mean "add into new entry".
正如ComFreek所正确指出的,您正在把$landing变成一个字符串。相反,如果您试图向着陆数组添加一个条目,请使用[]方括号,意思是“添加到新条目”。
$landing = array();
while ($row = mysqli_fetch_array($result)) {
$str = strtolower($row['Name']);
if ($str == $name) {
$landing[] = $row;
}
}
#3
-1
I cant comment LS97 post, anyway you want to use $landing["Name"] you edit LS97 code into this:
我不能评论LS97的文章,不管怎样,你想用$landing["Name"]你把LS97的代码编辑成这个:
$landing = array();
while ($row = mysqli_fetch_array($result)) {
$str = strtolower($row['Name']);
if ($str == $name) {
$landing["name"] = $row;
}
}
If you want to use multiple names, LS97 code is fine.
如果您希望使用多个名称,LS97代码是可以的。
The problem is what they said. (Using $landing = $row, landing will be a string.)
问题是他们说了什么。(使用$landing = $row, landing将是一个字符串。)
#1
3
The original code works somehow, now as the OP said in a comment.
正如OP在评论中所说,原始代码以某种方式工作。
But my old tips still hold:
但我的老建议仍然站得住脚:
- Consider using MySQLi or PDO instead of the deprecated MySQL extension!
- 考虑使用MySQLi或PDO,而不是废弃的MySQL扩展!
- Why do you compare the dataset's column value on the client-side? You can do this on the MySQL side, it'll be faster!
- 为什么要比较客户端上数据集的列值?你可以在MySQL这边做,它会更快!
#2
0
You are, as ComFreek correctly stated, turning $landing into a string. Instead, if you're trying to add an entry to the landing array, use [] brackets which mean "add into new entry".
正如ComFreek所正确指出的,您正在把$landing变成一个字符串。相反,如果您试图向着陆数组添加一个条目,请使用[]方括号,意思是“添加到新条目”。
$landing = array();
while ($row = mysqli_fetch_array($result)) {
$str = strtolower($row['Name']);
if ($str == $name) {
$landing[] = $row;
}
}
#3
-1
I cant comment LS97 post, anyway you want to use $landing["Name"] you edit LS97 code into this:
我不能评论LS97的文章,不管怎样,你想用$landing["Name"]你把LS97的代码编辑成这个:
$landing = array();
while ($row = mysqli_fetch_array($result)) {
$str = strtolower($row['Name']);
if ($str == $name) {
$landing["name"] = $row;
}
}
If you want to use multiple names, LS97 code is fine.
如果您希望使用多个名称,LS97代码是可以的。
The problem is what they said. (Using $landing = $row, landing will be a string.)
问题是他们说了什么。(使用$landing = $row, landing将是一个字符串。)