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

Reply

Join Date: Apr 2009
Posts: 2
Reputation: will910 is an unknown quantity at this point 
Solved Threads: 0
will910 will910 is offline Offline
Newbie Poster

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

 
0
  #1
Apr 10th, 2009
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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

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

 
0
  #2
Apr 10th, 2009
The query is failing, post the query and we might be able to fix it.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: will910 is an unknown quantity at this point 
Solved Threads: 0
will910 will910 is offline Offline
Newbie Poster

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

 
0
  #3
Apr 10th, 2009
what do you mean by post the query? this is the query.php file where its saying the error is its

  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

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

 
0
  #4
Apr 10th, 2009
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.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

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

 
0
  #5
Apr 10th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

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

 
0
  #6
Apr 11th, 2009
in line 25: $this->rs[] = mysql_query($sql);
put a [] after the rs.
or try to declare your var $rs = array();
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

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

 
0
  #7
Apr 13th, 2009
or that is an array so maybe you get the sizeof the array.

$this->totrows = mysql_num_rows(sizeof($this->rs));
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC