小弟初学PHP,编一个BLOG
然后出现如下错误,甚是迷糊,可能是我PHPADMIN用的不太明白,请指教!Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\PHPnowV1.5\PHPnow\PHPnow-1.5.4\htdocs\sites\blogtastic\index.php on line 10<?php
require("header.php");$sql="select entries.*,categories.cat FROM entries,categories
      where entries.cat_id=categories.id
      ORDER BY dateposted DESC
      LIMIT 1;";
$result = mysql_query($sql); $row = mysql_fetch_assoc($result);echo "<h2><a href='viewentry.php?id=".$row['id']."'>".$row['subject']."</a></h2><br/>";
echo "<i>In<a href='viewcat.php?id=".$row['cat_id']."'>".$row['cat']."</a>-Posted on".date("D jS F Y g.iA",strtotime($row['dateposted']))."</i>";
echo "<p>";
echo nl2br($row['body']);
echo "</p>";
require("footer.php");
?>以上是这个一面的源代码,帮我看看,谢谢啦~

解决方案 »

  1.   

    用数据库运行一下你的sql语句,看看什么效果.
      

  2.   

    $row = mysql_fetch_assoc($result); 
    这句出现问题.
    主要原因可能是因为你的sql语句有语法错误
    mysql_query函数后面,加上
    echo mysql_error();查看一下错误提示信息.
      

  3.   

    $sql="select entries.*,categories.cat FROM entries,categories 
          where entries.cat_id=categories.id 
          ORDER BY dateposted DESC 
          LIMIT 1;"; 可能错误:
    1 dateposted在两个表里都有这个字段,如果有,请在前面加上你需要按照操作的表名.
    2 字段或者表名写错了.呵呵.
      

  4.   

    照您的意思试了一下 告诉我 no selelcted database
      

  5.   

    参看手册实例,在连接完数据库以后,选取数据库.
    mysql_select_db(数据库名)
    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
    if (!$link) {
        die('Not connected : ' . mysql_error());
    }// make foo the current db
    $db_selected = mysql_select_db('foo', $link);
    if (!$db_selected) {
        die ('Can\'t use foo : ' . mysql_error());
    }