我有一个我从数据库构建的html表:
<tr onclick="DoNav('<?php echo $result_videos[$i]["video_url"]; ?>');">
<td>
<?php echo $result_videos[$i]["camera_name"]; ?>
</td>
<td>
Timezone: <?php echo queryTimezone(); ?> <br>
Video Size: <?php echo $result_videos[$i]["video_size"]; ?> bytes <br>
Video Length: <?php echo strTime($result_videos[$i]["video_length"]); ?>
</td>
<td>
<form name="myform" action="<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>" method="POST">
<input type="submit" name="delete_video" value="Delete" title="Delete this video" onClick="return confirm('Are you sure you want to delete?')"/>
<input type="hidden" name="video_url" value="<?php echo $result_videos[$i]["video_url"]; ?>" />
</form>
</td>
</tr>
问题在于这个功能:
function queryTimezone()
{
$query = "SELECT timezone FROM #__camcloud_users WHERE user_id=".$user->id;
$db->setQuery($query);
$timezone = $db->loadResult();
return $timezone;
}
它把桌子搞得一团糟。我似乎没有得到任何PHP错误,它在“时区:”部分切断表格,并将其扔到页面的右上角。基本上我称之为函数queryTimezone
。如果我改为将其放在html表中,它可以正常工作:
<tr onclick="DoNav('<?php echo $result_videos[$i]["video_url"]; ?>');">
<td>
<?php echo $result_videos[$i]["camera_name"]; ?>
</td>
<td>
Timezone: <?php
$query = "SELECT timezone FROM #__camcloud_users WHERE user_id=".$user->id;
$db->setQuery($query);
$timezone = $db->loadResult();
echo $timezone;
?> <br>
Video Size: <?php echo $result_videos[$i]["video_size"]; ?> bytes <br>
Video Length: <?php echo strTime($result_videos[$i]["video_length"]); ?>
</td>
<td>
<form name="myform" action="<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>" method="POST">
<input type="submit" name="delete_video" value="Delete" title="Delete this video" onClick="return confirm('Are you sure you want to delete?')"/>
<input type="hidden" name="video_url" value="<?php echo $result_videos[$i]["video_url"]; ?>" />
</form>
</td>
</tr>
这很好用。我是如何调用函数的?
答案 0 :(得分:3)
该函数无法确定$ user-&gt; id,因此无法返回有效结果...函数中没有定义$ user是什么
答案 1 :(得分:1)
请改用他的功能声明:
function queryTimezone($user,$db)
{
$query = "SELECT timezone FROM #__camcloud_users WHERE user_id=".$user->id;
$db->setQuery($query);
$timezone = $db->loadResult();
return $timezone;
}
这样打电话:
Timezone: <?php echo queryTimezone($user,$db); ?> <br>