1 Replies - 2544 Views - Last Post: 01 June 2011 - 04:34 AM Rate Topic: -----

#1 d.m14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 13-August 08

Call to a member function bind_param() on a non-object in

Posted 01 June 2011 - 04:04 AM

Hi guys,

I have a problem, I cannot see why I get this error Call to a member function bind_param() on a non-object in.

I am trying to run through a list of items user by user.

	
$users = "select distinct(user_id) as user from itemList";
	$result = mysqli_query($DBconnection,$users);
	
		while($row = mysqli_fetch_array($result))

			{
				$listofUsers[] = $row[0]; 
				
			}

		shuffle($userlist);
		//print_r($userlist);
	
$finished = false;
while(!$finished)
{	
	$finished = true;
   //iterate through userlist array of user id's
	
	echo "after while";
	foreach($listofUser as $user)

	{
	$result2 = $DBconnection->prepare("select item_id from itemlist where user_id = ?");

		$result2->bind_param("i", $user);
		$result2->execute();
		$result2->store_result();
		 
		 //check that is there is still a item in this user itemlist
        if($result2->num_rows > 0)
	{
       //echo"this is the user $user"; 

// get any items on this users itemlist
	
	
	$stmt = $DBconnection->prepare("SELECT item_id FROM itemlist where user_id = ? and isThere = 'yes'");
	
	$stmt->bind_param("i",$user);
	
	$stmt->execute();
	

	stmt_bind_assoc($stmt, $row);

// loop through all result rows
	echo "b4 if";
	if($stmt->fetch())
	{
	//echo $user;
	foreach($row as $i)
	{
	echo "this is $i in foreach";
    getPosition($row,$user);
	}
	}
	array_reverse($userlist);
	$finished = false;
	
	//echo"this is userlist";print_r($userlist);echo"<br>";	
	}
	}
	}
		



Is This A Good Question/Topic? 0
  • +

Replies To: Call to a member function bind_param() on a non-object in

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: Call to a member function bind_param() on a non-object in

Posted 01 June 2011 - 04:34 AM

chances are that your query failed to prepare. check the return value* of MySQLi->prepare().



* – PDO (the other DB system in PHP) can be instructed to throw exceptions instead of silently failing when a query can’t be prepared. PDO can also directly be put in a foreach() loop.

This post has been edited by Dormilich: 01 June 2011 - 04:35 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1