943,733 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1059
  • PHP RSS
Apr 10th, 2009
0

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

Expand Post »
hi im a newbie at this but im getting a error message that says:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/pickurau/public_html/classes/Lib/Query.php on line 27
and line 27 starts with the if(!mysql_affected_rows() || mysql_num_rows($this->rs) < 1)
return false;
does anyone know how can i fix this error?
heres the script code:
php Syntax (Toggle Plain Text)
  1. <?php
  2. class Lib_Query extends Lib_DbConnect
  3. {
  4. var $rs;
  5. var $totrows;
  6. var $records;
  7.  
  8.  
  9. /**
  10. * Enter description here...
  11. *
  12. * @param string $sql
  13. * @param array $fields
  14. * @return boolean
  15. */
  16. function executeQuery($sql, $fields = array())
  17. {
  18. //echo $sql,"<br/>";
  19. if(substr_count($sql,'#')!=count($fields))
  20. return false;
  21. if(count($fields)>0)
  22. $sql = $this->makeQuery($sql,$fields); // Security::makeQuery();
  23. $i=0;
  24.  
  25. $this->rs = mysql_query($sql);
  26.  
  27. if(!mysql_affected_rows() || mysql_num_rows($this->rs) < 1)
  28. return false;
  29. else
  30. {
  31. $this->totrows = mysql_num_rows($this->rs);
  32. while($fetch = mysql_fetch_array($this->rs))
  33. {
  34. $this->records[$i] = $fetch;
  35. $i++;
  36. }
  37. for($i=0;$i<count($this->records);$i++)
  38. {
  39. foreach ($this->records[$i] as $key=>$item)
  40. {
  41. if(is_numeric($key))
  42. unset($this->records[$i][$key]);
  43. }
  44. }
  45. return true;
  46. }
  47. }
  48.  
  49. /**
  50. * @param string $sql
  51. * @return boolean
  52. */
  53. function updateQuery($sql, $fields=array())
  54. {
  55.  
  56. if(substr_count($sql,'#')!=count($fields))
  57. return false;
  58. if(count($fields)>0)
  59. $sql = $this->makeQuery($sql,$fields); // Security::makeQuery();
  60.  
  61. $this->rs = mysql_query($sql);
  62. if(!$this->rs)
  63. return false;
  64. else
  65. return true;
  66. }
  67. }
  68. ?>
Last edited by peter_budo; Apr 12th, 2009 at 8:45 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
will910 is offline Offline
2 posts
since Apr 2009
Apr 10th, 2009
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

The query is failing, post the query and we might be able to fix it.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Apr 10th, 2009
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

what do you mean by post the query? this is the query.php file where its saying the error is its

php Syntax (Toggle Plain Text)
  1. <?php
  2. class Lib_Query extends Lib_DbConnect
  3. {
  4. var $rs;
  5. var $totrows;
  6. var $records;
  7.  
  8.  
  9. /**
  10. * Enter description here...
  11. *
  12. * @param string $sql
  13. * @param array $fields
  14. * @return boolean
  15. */
  16. function executeQuery($sql, $fields = array())
  17. {
  18. //echo $sql,"<br/>";
  19. if(substr_count($sql,'#')!=count($fields))
  20. return false;
  21. if(count($fields)>0)
  22. $sql = $this->makeQuery($sql,$fields); // Security::makeQuery();
  23. $i=0;
  24.  
  25. $this->rs = mysql_query($sql);
  26.  
  27. if(!mysql_affected_rows() || mysql_num_rows($this->rs) < 1)
  28. return false;
  29. else
  30. {
  31. $this->totrows = mysql_num_rows($this->rs);
  32. while($fetch = mysql_fetch_array($this->rs))
  33. {
  34. $this->records[$i] = $fetch;
  35. $i++;
  36. }
  37. for($i=0;$i<count($this->records);$i++)
  38. {
  39. foreach ($this->records[$i] as $key=>$item)
  40. {
  41. if(is_numeric($key))
  42. unset($this->records[$i][$key]);
  43. }
  44. }
  45. return true;
  46. }
  47. }
  48.  
  49. /**
  50. * @param string $sql
  51. * @return boolean
  52. */
  53. function updateQuery($sql, $fields=array())
  54. {
  55.  
  56. if(substr_count($sql,'#')!=count($fields))
  57. return false;
  58. if(count($fields)>0)
  59. $sql = $this->makeQuery($sql,$fields); // Security::makeQuery();
  60.  
  61. $this->rs = mysql_query($sql);
  62. if(!$this->rs)
  63. return false;
  64. else
  65. return true;
  66. }
  67. }
  68. ?>
Last edited by peter_budo; Apr 12th, 2009 at 8:45 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
will910 is offline Offline
2 posts
since Apr 2009
Apr 10th, 2009
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

I mean post the query. There is a query being passed to the 'executeQuery' function that is incorrect, that is why the function is failing.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Apr 10th, 2009
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

mysql_num_rows:
Retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows().

My guess would be that you're passing a fetched result like an array of the query.
Reputation Points: 26
Solved Threads: 9
Junior Poster in Training
brechtjah is offline Offline
92 posts
since Nov 2008
Apr 11th, 2009
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

in line 25: $this->rs[] = mysql_query($sql);
put a [] after the rs.
or try to declare your var $rs = array();
Reputation Points: 13
Solved Threads: 12
Junior Poster
rm_daniweb is offline Offline
165 posts
since Jan 2007
Apr 13th, 2009
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

or that is an array so maybe you get the sizeof the array.

$this->totrows = mysql_num_rows(sizeof($this->rs));
Reputation Points: 13
Solved Threads: 12
Junior Poster
rm_daniweb is offline Offline
165 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: problems with the ids ($_GET)
Next Thread in PHP Forum Timeline: displaying query results in a generated pdf doc





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC