Rhysyngsun Posted November 5, 2007 Share Posted November 5, 2007 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 5, 2007 Share Posted November 5, 2007 Don't add the trailing semicolon. Quote Link to comment Share on other sites More sharing options...
Rhysyngsun Posted November 5, 2007 Author Share Posted November 5, 2007 The presence or lack of semicolon in my sql statement made no difference. I actually added it at one point in the hopes it would resolve my issue. Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 Can we see your actual code? Quote Link to comment Share on other sites More sharing options...
Rhysyngsun Posted November 5, 2007 Author Share Posted November 5, 2007 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() ); } Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 5, 2007 Share Posted November 5, 2007 i dont know if this will help but try to remove the ' on your id $q = "SELECT * FROM `".TBL_CONTENT."` WHERE `id` = ".$id; Quote Link to comment Share on other sites More sharing options...
Rhysyngsun Posted November 5, 2007 Author Share Posted November 5, 2007 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. ??? Quote Link to comment Share on other sites More sharing options...
Rhysyngsun Posted November 6, 2007 Author Share Posted November 6, 2007 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"]; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.