[SOLVED] Working with multiple resultsets simultatiouly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hagar
Forum Newbie
Posts: 18
Joined: Mon May 20, 2002 3:28 am
Location: Johannesburg, South Africa

[SOLVED] Working with multiple resultsets simultatiouly

Post by Hagar »

I'm trying to retreive multiple result and using them. I have tried to pass the results to and array but PHP doesn't like it to much.

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, array given in C:\PHP\includes\.... on line 21
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post some code please. Specifically, the creation of the mysqli link or object, your query, and the code used for calling mysqli_fetch_array().
Hagar
Forum Newbie
Posts: 18
Joined: Mon May 20, 2002 3:28 am
Location: Johannesburg, South Africa

please help!

Post by Hagar »

Code: Select all

<?php
class result&#123;
	var $db;
	var $connect;
	var $result;

function result(&$connect)&#123;
	include("globals/Sianda_glb_conn.php");
	$this->connect = $connect;
	$this->db = $dbName;
&#125;

	function pages ($whereValue = "%",$page_requested,&$result,&$fieldName)&#123;
	$debug = 0;
		include("class/Select/scripts.php");
		$sql = new scripts();

		$debug = 0;

		switch($page_requested)&#123;

		case "MemProd":
			$this->result=mysqli_query($this->connect,$sql->Mem_List_script($whereValue)) or die("Invalid Query".mysql_error());
			$result&#1111;0] = $this->result;

			$this->result=mysqli_query($this->connect,$sql->Mem_Address_script($whereValue)) or die("Invalid Query".mysql_error());
			$result&#1111;1] = $this->result;

			$nRows=mysqli_num_rows($this->result);
			$numFileds = mysqli_num_fields($this->result);
			$fieldInfo = mysqli_fetch_fields($this->result);

			for($i=1; $i<$numFileds; $i++)&#123;
				$fieldName&#1111;$i] = $fieldInfo&#1111;$i]->name;
			&#125;


			if ($debug != 0)&#123;
				echo "result numbers: ".count($result)."<br>";
				echo "Connection: &#123;$this->connect&#125;";
				echo "<br> Numbers of Fields: &#123;$numFileds&#125;<br>";
				echo "Number of Rows: &#123;$nRows&#125;<br>";
			&#125;




			if ($debug != 0)&#123;
				echo "MemProd";
				echo "&#123;$sql->Mem_List_script($whereValue)&#125;<br>";
			&#125;
		break;

		if(count($result) == 1)&#123;
			$nRows=mysqli_num_rows($this->result);
			$numFileds = mysqli_num_fields($this->result);
			$fieldInfo = mysqli_fetch_fields($this->result);

			for($i=1; $i<$numFileds; $i++)&#123;
				$fieldName&#1111;$i] = $fieldInfo&#1111;$i]->name;
			&#125;

			if ($debug != 0)&#123;
				echo "Connection: &#123;$this->connect&#125;";
				echo "<br>Numbers of Fileds: &#123;$numFileds&#125;<br>";
				echo "Number of Rows: &#123;$nRows&#125;<br>";
			&#125;
		&#125;

	&#125;
&#125;
?>

getting the recordset from a switch

Code: Select all

<?php


	function vertical_display($result_num = 0,$page)&#123;
	include_once("class/html/html.php");
	include_once("class/select/results.php");

	$sql_class = new result($connect,$page);
	$html = new html();

	$whereValue ='%';
	$sql_class->pages($whereValue,$page,$result&#1111;$result_num],$fieldName);

		for($a=0; $a < count($result&#1111;$result_num]);$a++)&#123;

				$html->open_table("100%");
				$html->open_table_row();
				echo $result&#1111;$result_num];


				while($row=mysqli_fetch_array($result&#1111;$result_num]))&#123;
					for ($i=1; $i <= count($fieldName);$i++)&#123;
						$html->open_table_row();
							$html->open_table_data($fieldName&#1111;$i],"","1","tblhead");
							$html->close_table_data();
							$html->open_table_data($row&#1111;$i],"","1","tbldata");
							$html->close_table_data();
					$html->close_table_row();

				&#125;

				$html->open_table_row();
						$html->open_table_data("b","0%","");
						$html->close_table_data();
				$html->close_table_row();

				#echo "FieldName: &#123;$fieldName&#1111;$i]&#125;";

				&#125;

				$html->close_table_row();
				$html->close_table();
		&#125;
	&#125;
?>
The "class/select/results.php" path is where the class is. assume the the class has been instatiated and all the nice things.

All this works well if you are using one recordset only. :cry:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

check to see what "count($result[$result_num])" returns.. I'd guess 1, no matter what.
Hagar
Forum Newbie
Posts: 18
Joined: Mon May 20, 2002 3:28 am
Location: Johannesburg, South Africa

problem solved

Post by Hagar »

I fixed it a the place where I call the diferent results Thank you in any case.
Post Reply