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
class Lib_Query extends Lib_DbConnect 
{
	var $rs;
	var $totrows;
	var $records;
	
	
	/**
	 * Enter description here...
	 *
	 * @param string $sql
	 * @param array $fields
	 * @return boolean
	 */
	function executeQuery($sql, $fields = array())
	{
		//echo $sql,"<br/>";
		if(substr_count($sql,'#')!=count($fields))
			return false;
		if(count($fields)>0)
			$sql = $this->makeQuery($sql,$fields);	// Security::makeQuery();
		$i=0;

		$this->rs = mysql_query($sql);

		if(!mysql_affected_rows() || mysql_num_rows($this->rs) < 1)
			return false;
		else
		{
			$this->totrows = mysql_num_rows($this->rs);
			while($fetch = mysql_fetch_array($this->rs))
			{
				$this->records[$i] = $fetch;
				$i++;
			}
			for($i=0;$i<count($this->records);$i++)
			{
				foreach ($this->records[$i] as $key=>$item)
				{
					if(is_numeric($key))
						unset($this->records[$i][$key]);
				}
			}
			return true;
		}
	}

	/**
	 * @param string $sql
	 * @return boolean
	 */
	function updateQuery($sql, $fields=array())
	{
	  
		if(substr_count($sql,'#')!=count($fields))
			return false;
		if(count($fields)>0)
			$sql = $this->makeQuery($sql,$fields);	// Security::makeQuery();

		$this->rs = mysql_query($sql);
		if(!$this->rs)
			return false;
		else
			return true;
	}	
}
?>

Recommended Answers

All 6 Replies

The query is failing, post the query and we might be able to fix it.

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

<?php
class Lib_Query extends Lib_DbConnect
{
var $rs;
var $totrows;
var $records;


/**
* Enter description here...
*
* @param string $sql
* @param array $fields
* @return boolean
*/
function executeQuery($sql, $fields = array())
{
//echo $sql,"<br/>";
if(substr_count($sql,'#')!=count($fields))
return false;
if(count($fields)>0)
$sql = $this->makeQuery($sql,$fields); // Security::makeQuery();
$i=0;

$this->rs = mysql_query($sql);

if(!mysql_affected_rows() || mysql_num_rows($this->rs) < 1)
return false;
else
{
$this->totrows = mysql_num_rows($this->rs);
while($fetch = mysql_fetch_array($this->rs))
{
$this->records[$i] = $fetch;
$i++;
}
for($i=0;$i<count($this->records);$i++)
{
foreach ($this->records[$i] as $key=>$item)
{
if(is_numeric($key))
unset($this->records[$i][$key]);
}
}
return true;
}
}

/**
* @param string $sql
* @return boolean
*/
function updateQuery($sql, $fields=array())
{

if(substr_count($sql,'#')!=count($fields))
return false;
if(count($fields)>0)
$sql = $this->makeQuery($sql,$fields); // Security::makeQuery();

$this->rs = mysql_query($sql);
if(!$this->rs)
return false;
else
return true;
}
}
?>

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.

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.

in line 25: $this->rs[] = mysql_query($sql);
put a [] after the rs.
or try to declare your var $rs = array();

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

$this->totrows = mysql_num_rows(sizeof($this->rs));

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.