我想打印出返回函数的值,我的主要目的是从不同的文件中调用函数,我已经用不同的函数做了好几次,但是这似乎没有用,我不能算出来。请帮忙。
swifty.php
include_once('core/init.php');
$errorno = 'Please contact the administrator, Quoting err no : q2913, Q Issues referring to: ' . mysqli_error($con);
function getStatus_update() {
$user_id = (int) $user_data['id'];
$result = mysqli_query($con, "SELECT * FROM users_status WHERE `user_id` = '$user_id` ORDER BY `date_posted` DESC'");
$update = array();
while ($row = mysqli_fetch_array($result)) {
$update[] = $row;
}return $update;
}
user.php的
<?php
include_once 'swifty.php';
$rand = getStatus_update();
foreach ($rand as $k => $v) {
var_dump($v['status']);
}
没有任何反应,没有错误消息,也没有返回任何值。
答案 0 :(得分:1)
$user_data
函数
$con
和getStatus_update()
都不在scope
include_once('core/init.php');
$errorno = 'Please contact the administrator, Quoting err no : q2913, Q Issues referring to: ' . mysqli_error($con);
function getStatus_update($con, $user_data) {
$user_id = (int) $user_data['id'];
$result = mysqli_query($con, "SELECT * FROM users_status WHERE `user_id` = '{$user_id}' ORDER BY `date_posted` DESC");
$update = array();
while ($row = mysqli_fetch_array($result)) {
$update[] = $row;
}
return $update;
}
和
$rand = getStatus_update($con, $user_data);
foreach ($rand as $k => $v) {
var_dump($v['status']);
}
如果您刚刚开始学习PHP,那么也要学会在SQL查询中使用绑定变量
答案 1 :(得分:0)
您可能还想设置包含路径