在与其所属类不同的页面上打印数组
我有这个数组,我想在其他地方打印它。 我已将其存储在 user.class.php 中,但我想将其打印在 Feedback.php 中。
我该怎么做?因为它一直告诉我它不知道“$myarray”。
请帮忙:)谢谢。
public function getFeedback($p_iUserid) {
include("Connection.php"); //open db
try
{
$sql = "SELECT FeedbackPatient FROM tblFeedback
WHERE fk_UserId = ".$p_iUserid."";
$result = mysqli_query( $link, $sql );
while( $row=mysqli_fetch_assoc($result) )
{
$myarray[] = $row['FeedbackPatient'];
print_r($myarray);
}
mysqli_free_result( $result );
}
catch(Exception $e)
{
// no connection database
$feedback = $e->getMessage();
}
mysqli_close($link);
}
I have this array and I want to print it somewhere else.
I have stored it in a user.class.php but I want to print it in feedback.php.
How do I do this? Because it keeps on telling me that it doesn't know '$myarray'.
Please help :) Thanks.
public function getFeedback($p_iUserid) {
include("Connection.php"); //open db
try
{
$sql = "SELECT FeedbackPatient FROM tblFeedback
WHERE fk_UserId = ".$p_iUserid."";
$result = mysqli_query( $link, $sql );
while( $row=mysqli_fetch_assoc($result) )
{
$myarray[] = $row['FeedbackPatient'];
print_r($myarray);
}
mysqli_free_result( $result );
}
catch(Exception $e)
{
// no connection database
$feedback = $e->getMessage();
}
mysqli_close($link);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我只是将其作为函数的返回:
然后在
feedback.php
中:I would just make it a return of the function:
Then in
feedback.php
:如果
myarray
是user
类的属性,那么在您的 Feedback.php 页面中,您将需要:user
类的实例(例如$user = new user();
)myarray
:$user->myarray
If
myarray
is an attribute of the classuser
, then in your feedback.php page, you would need:user
(e.g.$user = new user();
)myarray
by using this syntax:$user->myarray
另一种方法是将数组序列化并存储在会话变量中:
Another way is to serialize and store the array in a session variable: