0

I'm getting an error:
mysql_fetch_array(): supplied argument is not a valid MySQL result resource

function next_record()
		{
		$this->myrow = mysql_fetch_array($this->result);
		return $this->myrow;
		}

Please help!

4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by mamari
0

Can we see the rest of the class, or at least see where $this->result is assigned a value?

0
class DB
	{
	function DB ($db_host="",$db_login="",$db_password="",$db_name="")
		{
		global $DB_HOST;
		global $DB_LOGIN;
		global $DB_PASSWORD;
		global $DB_NAME;
		if($db_host == "") $db_host = $DB_HOST;
		if($db_login == "") $db_login = $DB_LOGIN;
		if($db_password == "") $db_password = $DB_PASSWORD;
		if($db_name == "") $db_name = $DB_NAME;
		$this->db_link = mysql_connect("$db_host","$db_login","$db_password");
		if(!$this->db_link)
			die("<font color=red bgcolor=white>Database problem</font>");
		mysql_select_db("$db_name",$this->db_link);
		}

	function query($query)
		{
		$this->result = mysql_query($query,$this->db_link);
		if (mysql_error($this->db_link) != "")
			echo "<font color=#256ACE>Error MYSQL: </font><font color=red>" . mysql_error($this->db_link) . "</font><br><font color=#256ACE>Query:</font> <font color=red>$query<br></font>";
		else
			return $this->result;
		}
		
	function next_record()
		{
		$this->myrow = mysql_fetch_array($this->result);
		return $this->myrow;
		}
		
	function get($column)
		{
		return $this->myrow["$column"];
		}

	function num_rows()
		{
		return mysql_num_rows($this->result); 
		}

	function insert_id()
		{
		return mysql_insert_id($this->db_link);
		}
	}
0
function show_head($lang,$p)
	{
	$q = new DB;
	$q->query("select title from contenu_sections where id = $p");
	$q->next_record();
	$title = $q->get("title");
	$q->query("select title,keyword,description from contenu_config_lang where lang = $lang");
	$q->next_record();
	if($title == "")
	$title = $q->get("title");
	$keyword = $q->get("keyword");
	$description = $q->get("description");
	printf("\n<title>$title</title>\n");
	if($keyword != "")
		echo "<meta name=\"keywords\" content=\"$keyword\">\n";
	if($description != "")
		echo "<meta name=\"description\" content=\"$description\">\n";
	echo "<script language=javascript>
	function pop_win(url,w,h,win_name,scroll)
		{
		if(scroll)
			scroll = 'yes';
		else
			scroll = 'auto';
  		var left = (screen.width-w)/2;
  		var top= (screen.height-h)/2;
  		window.open(url,win_name,'resizable=yes,scrollbars='+scroll+',menubar=no,status=no,width='+w+',height='+h+',left='+left+',top='+top);
		}
		</script>";
	return;
	}
	
function load_page($p="",$show_section_name=0,$sub=0)
	{
	global $lang;
	global $sub;
	$q = new DB;
	if(!$sub)
		$query = "select default_section_id sec_id from contenu_default_section where section_id = $p order by order_no";
	else
		$query = "select id sec_id from contenu_sections where master_section = $p order by order_no";
	$q->query($query);
	$x=0;
	if($q->num_rows() != 0)
		{
		while($q->next_record())
			{
			$x++;
			show_page($q->get("sec_id"),$x,$show_section_name);
			}
		}
	else
		show_page($p,'',$show_section_name);
	return $p;
	}
0

Is it possible that you have to do this?:

$q->query("select title from contenu_sections where id = '$p'");

I've come across this problem and the query was not accepting the variable unless I added inverted single commas.

Edited by charlybones: Added info

0

Check through by adding mysql_error() in executing query.
On line 21, replace this part.

$this->result = mysql_query($query,$this->db_link) or die(mysql_error());
0

Thank you very much Charly, resolved!

Edited by mamari: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.