如何在一页中多次回显数组?
我想知道是否有人可以帮助我解决这个问题。 我想在同一页面上多次打印/回显该函数的解决方案。这可能吗?
这是我的函数:
public function getFeedback($p_iUserid) {
include("Connection.php"); //open db
try
{
$sql = "select DiaryOpmerkingen, DiaryDoctorcomment from tblDiary
WHERE fk_UserId = ".$p_iUserid."
AND DiaryDay = '".$this->Day."';";
$rResult = mysqli_query($link, $sql);
return $rResult;
}
catch(Exception $e)
{
// no connection database
$feedback = $e->getMessage();
}
mysqli_close($link);
}
这就是我现在设法调用该函数的方式。但它只能工作一次:
if(mysqli_num_rows($feedbackPatient) > 0)
{
while($oUser = mysqli_fetch_assoc($allUsers))
{
echo $oUser['DiaryOpmerkingen'];
}
}
我希望有人能帮忙! 不管怎样,谢谢。
I was wondering if someone could help me with this problem.
I want to print/echo the solution of the function multiple times on the same page. Is that possible?
Here's my function:
public function getFeedback($p_iUserid) {
include("Connection.php"); //open db
try
{
$sql = "select DiaryOpmerkingen, DiaryDoctorcomment from tblDiary
WHERE fk_UserId = ".$p_iUserid."
AND DiaryDay = '".$this->Day."';";
$rResult = mysqli_query($link, $sql);
return $rResult;
}
catch(Exception $e)
{
// no connection database
$feedback = $e->getMessage();
}
mysqli_close($link);
}
And this is how I manage to call on the function by now. But it only works once:
if(mysqli_num_rows($feedbackPatient) > 0)
{
while($oUser = mysqli_fetch_assoc($allUsers))
{
echo $oUser['DiaryOpmerkingen'];
}
}
I hope someone can help!
Thanks anyway.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为您的打印任务创建一个函数,然后根据需要多次调用它:
然后,无论您需要在哪里打印:
Create a function for your printing task, then call it as many times as you want:
Then, wherever you need to print:
最简单的方法可能是一次性获取整个结果集,然后将其传递。
如果结果集很大,这可能会降低性能,但可能不会产生显着差异。使用 mySqli 扩展尤其容易,因为您可以使用
mysql_fetch_all
。然后,您将获得从 getFeedback 返回的关联数组,并且可以像平常一样循环遍历:
The easiest way to do this is probably to get the whole result set in one go, and then pass that around.
This might be costly in terms of performance if the result set is large, but it's probably not going to make a significant difference. It is particularly easy with the mySqli extension, because you can use
mysql_fetch_all
.You would then get an associative array returned from
getFeedback
, and could loop through this as normal:我认为应该是:
为什么你对 mysqli_num_rows 和 sqli_fetch_assoc 使用 diff 结果?
I think it should be :
why are u using diff result for mysqli_num_rows and sqli_fetch_assoc ?