【发布时间】:2014-01-03 10:02:04
【问题描述】:
我不知道怎么了,我明白了:
警告:mysql_fetch_array() 期望参数 1 是资源,在中给出布尔值。
我的fetch_array 有问题。它在
第 34 行 while($row = mysql_fetch_array($sql))
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("blog1");
?>
<!DOCTYPE html>
<html>
<head>
<title>BLOGGEN</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="css/kickstart.css" media="all" />
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="js/kickstart.js"></script>
</head>
<body>
<ul class="menu">
<li class="current"><a href="index.php">Hem</a>
</li>
<li><a href="blogg.php">Din Blogg</a>
</ul>
<?php
$sql = mysql_query("SELECT * FROM blogdata ORDER BY id DESC");
while($row = mysql_fetch_array($sql)){
$title = $row["title"];
$content = $row["content"];
$category = $row["category"];
?>
<table border = "1">
<tr><td><?php echo $title; ?></td><td><?php echo $category; ?></td></tr>
<tr><td colspan="2"><?php echo $content; ?></td></tr>
</table>
<?php
}
?>
</div>
</div>
</body>
</html>
【问题讨论】:
-
停止使用 mysql_* 并改用 pdo/mysqli? @tomexsans 已编辑;)
-
您可能会从查询中得到
false。 -
回显您的查询,然后在 phpmyadmin 或 sqlyog 执行它...
-
调试发生了什么。
-
@tomexsans - Stackoverflow:自 2008 年以来的众包调试:P