我正在尝试创建一个函数,它将返回一个mysql查询,然后我可以循环遍历并处理结果,但似乎无法正常工作。我可能甚至没有用正确的方法。
function GetAccounts($username){
require("dbconn.php");
$result = mysql_query("SELECT * FROM `accounts` WHERE `username` = '$username' ") or trigger_error(mysql_error());
return "$result";
}
$result = GetAccounts($username);
while($row = mysql_fetch_array($result)){
foreach($row AS $key => $value) { $row[$key] = stripslashes($value); }
$theusername = $row['theusername'];
$thepassword = $row['thepassword'];
echo $theusername;
}
我收到的错误信息是
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
我尝试将上述所有内容加载到函数中,但每次只能得到单个结果。由于我需要处理每个结果,所以“我认为”上述方法是我想要的方式,但如果有更好的方式或者我做错了什么,请告诉我。
当我使用用户名回显函数时,我得到以下结果:
Resource id #5