Hello,

I am getting the following error message:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/mochas/domains/zoink.sx33.net/public_html/includes/blogpost.php on line 54

My code (Line 54):

while($row = mysql_fetch_assoc($query))

Recommended Answers

All 6 Replies

Member Avatar for LastMitch

@paulmcdoodles

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/mochas/domains/zoink.sx33.net/public_html/includes/blogpost.php on line 54

You know it would be nice to actually see the whole code instead of 1 line of code.

So you are having an error on here:

while($row = mysql_fetch_assoc($query))

The error means your $query is not connected to the DB or not selecting any data.

@LastMitch

Here is the FULL code:

<?php

class BlogPost
{

public $id;
public $title;
public $post;
public $author;
public $tags;
public $datePosted;
public $signature;

function __construct($inId=null, $inTitle=null, $inPost=null, $inPostFull=null, $inAuthorId=null, $inDatePosted=null, $signature = null)
{
    if (!empty($inId))
    {
        $this->id = $inId;
    }
    if (!empty($signature))
    {
        $this->signature = stripslashes($signature);
    }
    if (!empty($inTitle))
    {
        $this->title = $inTitle;
    }
    if (!empty($inPost))
    {
        $this->post = str_replace("<br><br>", "<br>", stripslashes($inPost));
    }

    if (!empty($inDatePosted))
    {
        $splitDate = explode("-", $inDatePosted);
        $this->datePosted = $splitDate[1] . "/" . $splitDate[2] . "/" . $splitDate[0];
    }

    if (!empty($inAuthorId))
    {
        $query = mysql_query("SELECT * FROM people WHERE id = " . $inAuthorId);
        $row = mysql_fetch_assoc($query);
        $this->author = $row["first_name"] . " " . $row["last_name"];
        $sig = $row["signature"];
        $this->signature = $sig;
    }

    $postTags = "No Tags";
    if (!empty($inId))
    {
        $query = mysql_query("SELECT tags.* FROM blog_post_tags LEFT JOIN (tags) ON (blog_post_tags.tag_id = tags.id) WHERE blog_post_tags.blog_post_id = " . $inId);
        $tagArray = array();
        $tagIDArray = array();
        while ($row = mysql_fetch_assoc($query)) {
        {
            array_push($tagArray, $row["name"]);
            array_push($tagIDArray, $row["id"]);
        }
        if (sizeof($tagArray) > 0)
        {
            foreach ($tagArray as $tag)
            {
                if ($postTags == "No Tags")
                {
                    $postTags = $tag;
                }
                else
                {
                    $postTags = $postTags . ", " . $tag;
                }
            }
        }
    }
    $this->tags = $postTags;
}

}
?>
Member Avatar for LastMitch

@paulmcdoodles

Did you write this code?

You should understand that you are using OOP? Did you know that?

$query = mysql_query("SELECT tags.* FROM blog_post_tags LEFT JOIN (tags) ON (blog_post_tags.tag_id = tags.id) WHERE blog_post_tags.blog_post_id = " . $inId);

Are you connected to the Database?

You need to fixed the query into for it to work.

Can you tell me how to fix it, or fix it for me, I'm not really good with PHP. Thanks, much appreciated!

Member Avatar for LastMitch

@paulmcdoodles

Can you tell me how to fix it, or fix it for me, I'm not really good with PHP. Thanks, much appreciated!

No, I'm not gonna fixed for you. If you're not familiar with PHP then my advice is to learn it.

Here is a link you can learn about MYSQL

http://www.w3schools.com/sql/default.asp

Nevermind then, I don't know how to fix it and simply don't have time to learn PHP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.