php - 无法在函数 PHP 中获取数组

标签 php mysql arrays function fetch

我无法在函数内获取数组,但可以在函数外获取。当我在函数外部获取它并将其回显时,它打印出 1,但在函数内部,使用相同的获取数组代码并将其回显,它回显为 null。我知道是因为 --- 符号回显了,但数字 1 没有。我很困惑,因为如果它在函数外工作,同样的代码应该在函数内工作,对吧?除非我做错了什么?请帮忙。谢谢。

<?php

include('connect.php');
include('username.php');
//include('functionGet.php');

$boo = $_GET['boo'];
echo "$boo";

function getData($select,$from,$where,$equals){

$fetch = mysql_fetch_array(mysql_query("SELECT acceptedChallenges FROM      
userLogin WHERE username = '$username'"));
$fetch = $fetch['acceptedChallenges'];

echo "---$fetch---";

}

if($boo = 'yes'){

$acceptedChallenges =    
getData("acceptedChallenges","userLogin","username",$username);

$fetch = mysql_fetch_array(mysql_query("SELECT acceptedChallenges FROM    
userLogin WHERE username = '$username'"));
$fetch = $fetch['acceptedChallenges'];

echo "$acceptedChallenges$username$fetch";

//mysql_query("UPDATE userLogin SET openChallenges = '0' WHERE username =   
'$username'");
//mysql_query("UPDATE userLogin SET acceptedChallenges =   
'$acceptedChallenges' WHERE username = '$username'");

}
else{



}
?>

最佳答案

你传递的是 $where 而不是 $username 所以改变

 function getData($select,$from,$where,$equals){

 function getData($select,$from,$username,$equals){

关于php - 无法在函数 PHP 中获取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30247361/

相关文章:

javascript - 发送空白电子邮件的 PHP 脚本无法获取发布数据

php - WordPress 导入错误

mysql - 获取行集中一行的排名

php - 我如何在 laravel 中对两个不同的 Controller 功能方法使用相同的路由

ios - 快捷代码(根据数量隐藏 View )

php - 统一排列/分布数组项

php - 在模式对话框中隐藏服务器端数据

MySQL : How to automatically insert values on following FK columns?

arrays - 使用 Swift 需要检查一个 Int 数组看它们加起来是否等于 10

php - 在 Doctrine/Symfony 3 中创建类似 SQL 触发器的东西