Topic: Newbie With most likely a simple question!

I am working out of a book and I'm trying to run this code.

    $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 " ,
            strtotime($row['dateposted'])) .
            "<i>";
            echo "<p>";
            echo nl2br($row['body']);
            echo "</p>";


  When I do I get this error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

Can anyone help me out here. Also thanks in advance.

Vote up Vote down

Re: Newbie With most likely a simple question!

what is the line above your code sample, where you set the $sql variable?

Should be something along the lines of

$sql = ...sql query here...

An incorrectly coded query could cause the problem.

Benjamin Falk | Falken Creative : Twitter
Skills: Photoshop, Illustrator, HTML, CSS, jQuery, PHP and CodeIgniter

Vote up Vote down

Re: Newbie With most likely a simple question!

$sql = "SELECT entries.*, categories.cat FROM entriesm, categories
        WHERE entries.cat_id = categories.id
        ORDER BY dateposted DESC
        LIMIT 1;";

Vote up Vote down

Re: Newbie With most likely a simple question!

I just got it thank you for the help I must have over looked this too many time.

Vote up Vote down