有人可以指出这段代码的问题吗?它应该从mysql获取数据,但它返回空白。这是完整的代码。
<ul class="list">
<?php
require("object/db.class.php");
error_reporting(0);
function entry_tickets() {
if($_SESSION['dojopress_global:root'] == false) {
$entry_ticket .= <<<ENTRY_TICKET
<li><p><img src="http://cdn1.iconfinder.com/data/icons/humano2/32x32/apps/gnome-keyring-manager.png" />Access denied</p></li>
ENTRY_TICKET;
} elseif($_SESSION['dojopress_global:root'] == true) {
$q = "SELECT * FROM `notice` ORDER BY nid LIMIT 12 DESC";
$r = mysql_query($q);
if ( mysql_num_rows($r) == 0 ) {
$entry_ticket .= <<<ENTRY_TICKET
<li><p><img src="http://cdn1.iconfinder.com/data/icons/humano2/32x32/status/dialog-information.png" /> Nothing to display</p></li>
ENTRY_TICKET;
} elseif ( $r !== false && mysql_num_rows($r) > 0 ) {
while ( $a = mysql_fetch_array($r) ) {
$nid = stripslashes($a['nid']);
$note = stripslashes($a['note']);
$type = stripslashes($a['type']);
$private = stripslashes($a['private']);
$date = stripslashes($a['date']);
$author = stripslashes($a['author']);
function note_type($type) {
if($type == 1) { $type = "posted a comment!"; } elseif($type == 2) { $type = "raised a support ticket!"; } else { }
return ($type);
}
$entry_ticket .= <<<ENTRY_TICKET
<li><p><a href="viewer.php?nid=$nid" id="record-$nid"> $athor, note_type($type)</a></p></li>
ENTRY_TICKET;
return $entry_ticket;
}
}
}
}
echo entry_tickets();
?>
</ul>
<div style="clear:both;height:10px;"></div>
抱歉忘了db.class.php
<?php
session_start();
//connect.php
$host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "au";
$connectClass = mysql_connect("$host", "$db_user", "$db_pass") or die ("Couldn't establish connection to database server.");
$dbObject = mysql_select_db("$db_name", $connectClass) or die ("Couldn't select database.");
?>
错误报告已禁用错误代码
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\wamp\www\ageis\note.php on line 22
答案 0 :(得分:4)
你的mysql语法看起来很糟糕。你有:
SELECT * FROM `notice` ORDER BY nid LIMIT 12 DESC
尝试
SELECT * FROM `notice` ORDER BY nid DESC LIMIT 12
Erik的评论应该指出你正确的方向,但是:
答案 1 :(得分:2)
您每次通过while循环重新定义function note_type
。你在函数外面有一个return
调用,在它下面。真的,我看不出这在句法上是否正确。看起来你的括号不匹配会有很大的问题。
对于实际的数据库问题,如果没有行从调用返回,则应检查mysql_error(),因为它可能出错了。
另外,我建议使用PDO
这是一个真正的数据库类,而不是基于本机函数的类。