好的,所以我有两个文件,
manageDay.php db_connect.php
db_connect.php包含在带有require_once 'db_connect.php';
文件位于同一位置(同一文件夹)
manageDay.php的重要部分如下:
<?php
require_once 'db_connect.php';
ini_set ("display_errors", "1");
error_reporting(E_ALL);
mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$user_id = $_GET['user_id'];
$date = $_GET['date'];
?>
这将调用包含数据库连接详细信息的附带文件以及一些函数。
<?
while ($row = mysql_fetch_assoc(getHoursForDay($date, $user_id))) {
/*while ($row = mysql_fetch_assoc($result)) {*/
echo '
<tr>
<td>'.$row['code'].'
</td>
<td>'.$row['project'].'
</td>
<td>'.$row['job'].'
</td>
<td>'.$row['start_time'].'
</td>
<td>'.$row['end_time'].'
</td>
<td>'.$row['location'].'
</td>
<td></td>
</tr>
';
}
?>
第二位调用记录集,该记录集由于db_connect.php
以下是db_connect.php
:
<?php
$db_hostname = "localhost";
$db_username = "xxxxx_ts";
$db_password = "xxxxxxx";
$db_name = "xxxxx_ts";
function getHoursForDay($date, $user_id){
$sql = "SELECT *
FROM bt_hours
INNER JOIN bt_location ON bt_hours.location_id = bt_location.id
INNER JOIN bt_projects ON bt_hours.project_id = bt_projects.id
WHERE bt_hours.user_id='$user_id' AND bt_hours.work_date LIKE '$date'";
$result = mysql_query($sql)
or die(mysql_error());
return $result;
}
?>
调用的网址为manageDay.php?date=2015-01-02&user_id=2
当我调用页面时,它会返回:
Fatal error: Call to undefined function getHoursForDay() in /var/www/vhosts/xxxxx.com/ts.xxxxx.com/api/sql/manageDay.php on line 53
但是,如果我删除该功能,并将其内容放在manageDay.php中,它可以正常工作吗?请注意,仍在从db_connect.php
<?
$sql = "SELECT *
FROM bt_hours
INNER JOIN bt_location ON bt_hours.location_id = bt_location.id
INNER JOIN bt_projects ON bt_hours.project_id = bt_projects.id
WHERE bt_hours.user_id='$user_id' AND bt_hours.work_date LIKE '$date'";
$result = mysql_query($sql)
or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
/*while ($row = mysql_fetch_assoc($result)) {*/
echo '
<tr>
<td>'.$row['code'].'
</td>
<td>'.$row['project'].'
</td>
<td>'.$row['job'].'
</td>
<td>'.$row['start_time'].'
</td>
<td>'.$row['end_time'].'
</td>
<td>'.$row['location'].'
</td>
<td></td>
</tr>
';
}
?>
任何人都可以帮助我理解为什么会这样吗?我不会认为自己是一个有成就的编码器,但如果我在这里遗漏了一些东西......
干杯
答案 0 :(得分:0)