Jump to content

mysql_fetch_array(): supplied argument is not a valid MySQL result..please help!


Recommended Posts

Please help me, can't figure out what i am doing wrong.

Error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\pharma_edu\lib\database.php on line 22

This is all the code needed for you to see what the problem might be.

<?php
# Connects to database server and selects database.
# Returns bool.
function db_connect() 
{
	$connection = mysql_pconnect(HOST, USERNAME, PASSWORD);
	if (!$connection)
	{
		return false;
	}
	if (!mysql_select_db(DATABASE))
	{
		return false;
	}
	return $connection;
}
# Turns MYSQL resource into array.
# Returns Array.
  function result_to_array($result)
{
  $result_array = array();
	for ($i=0; $row = mysql_fetch_array($result) ; $i++)
	{
	   $result_array[$i] = $row; 
	}

	return $result_array;
}
function courses_list()
{
	db_connect();

	$result_count = mysql_query("SELECT * FROM courses_available");
	$num_rows = mysql_num_rows($result_count);

	$result = array();

	for ($i = 1; $i <= $num_rows; $i++) {
		$query1 = "SELECT * FROM courses_available WHERE courses_available.id = '$i'";
		$result1 = mysql_query($query1);
		$result1 = result_to_array($result1);

		$course_id = $result1['course_id'];

		$query2 = "SELECT * FROM courses_list WHERE courses_list.course_id = '$course_id'";
		$result2 = mysql_query($query2);
		$result2 = result_to_array($result2);
		array_merge($result1, $result2, $result);
	}
	return $result;
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.