这个问题在这里已经有了答案:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 个回答)
8年前关闭。
我正在尝试制作新闻页面,但出现此错误
Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\News\Index.php on
第 37 行
这是代码
$category = mysql_query("SELECT icon FROM website.catnews WHERE ncatid=\'". mysql_real_escape_string($news['category']). '\'');
echo '<td>
<td><a href = "news.php?cat='. $news['category'].'"><img src="./img/'.mysql_result($category, 'icon').'" alt="" /></a></td>';
这是 mssql 中的全部源代码
<br />
<table style="width: 100%;">
<tr>
<td></td>
<td id="key">Title</td>
<td id="key" style="text-align: center;">Author</td>
<td id="key" style="text-align: center;">Comments</td>
<td id="key" style="text-align: center;">Views</td>
<td id="key" style="text-align: center;">Date</td>
</tr>
<?php
odbc_exec($mssql, 'USE [WEBSITE_DBF]');
$count = odbc_exec($mssql, 'SELECT COUNT(*) as count FROM [web_news]');
if(odbc_result($count, 'count') > 0) {
$query = odbc_exec($mssql, 'SELECT TOP 10 * FROM [web_news] ORDER BY datetime DESC');
while($news = odbc_fetch_array($query)) {
$title = $news['title'];
if(strlen($title) > 35) {
$title = substr($title, 0, 35).'...';
}
$comments = odbc_exec($mssql, 'SELECT COUNT(*) as count FROM [web_newscomments] WHERE nid=\''.mssql_escape_string($news['nid']).'\'');
$category = odbc_exec($mssql, 'SELECT icon FROM [web_newscategories] WHERE ncatid=\''.mssql_escape_string($news['category']).'\'');
echo '<tr>
<td><a href="news.php?cat='.$news['category'].'"><img src="./img/'.odbc_result($category, 'icon').'" alt="" /></a></td>
<td><a href="news.php?nid='.$news['nid'].'">'.$title.'</a></td>
<td style="text-align: center;">'.$news['author'].'</td>
<td style="text-align: center;">'.odbc_result($comments, 'count').'</td>
<td style="text-align: center;">'.$news['views'].'</td>
<td style="text-align: center;">'.date('Y-m-d', strtotime($news['datetime'])).'</td>';
}
} else {
echo 'No news available!';
}
?>
</table>
最佳答案
解决了!
将图标表部分移到新闻表中
并使用:
<td><a href="news.php?cat='.$news['category'].'"><img src="./img/'. $news['icon'] .'" alt="" /></a></td>
instead of
<td><a href="news.php?cat='.$news['category'].'"><img src="./img/'.odbc_result($category, 'icon').'" alt="" /></a></td>
关于PHP Mysql 获取字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20820400/