Jump to content

[SOLVED] Supplied argument is not a valid MySQL result resource


Recommended Posts

I get the following Error:

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in content.php on line 69

 

I also get this error when performing other MySQL function on this particular result.

 

The code that create my sql query is as follows:

 

$q = "SELECT * FROM `".TBL_CONTENT."` WHERE `id` = '8';";

 

This generates the following sql (with 8 assigned to $this->id and "content_tbl" assigned to TBL_CONTENT):

 

SELECT * FROM `content_tbl` WHERE `id` = '8';

 

I know this query works, as I do have a row with id set to 8 and I ran the query in phpMyAdmin and got the correct results. It is also not a connection issue as I am able to promptly delete that very row after the SELECT query.

 

I've also Googled my keyboard into the ground trying to figure this out so any help would be much appreciated.

Contained in a class that handles my content:

 

public function getContentByID( $id ) {		

# Construct query string
$q = "SELECT * FROM `".TBL_CONTENT."` WHERE `id` = '$id'";

# Send query
$result = $this->database->query( $q );

# Get our row
if( $row = mysql_fetch_row( $result ) ) {	
	# Store data
	$this->id = $row["id"];
	$this->title = $row["title"];
	$this->content = $row["data"];
	$this->parentid = $row["parentid"];
} else mysql_error();
}

 

$this->database is an object that keeps track of the connection and provides a query function as follows:

 

public function Query( $query ) {
return mysql_query( $query, $this->conn ) or die( mysql_error() );
}

I still get the error. I even tried hard coding the SQL command with the one that works is supposedly generated and works only in phpMyAdmin so that there's no issues about string concatenation or variables.

 

I was really hoping this was some silly mistake brought on by tunnel vision. ???

It apparently fixed itself. Not sure why. Here's my final code (the original code also runs fine  ::)):

 

# Construct query string
$q = "SELECT * FROM `".TBL_CONTENT."` WHERE `id` = '$id'";

# Send query
$result = $this->database->query( $q );

# Get our row
if( $result ) {
if( $row = mysql_fetch_assoc( $result ) ) {	
	# Store data
	$this->id = $row["id"];
	$this->title = $row["title"];
	$this->data = $row["data"];
	$this->parentid = $row["parentid"];
} 
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.