Jump to content

mysql UNION | warning mysql_fetch_array !!


subash85

Recommended Posts

<?php
		$i = 0;
		$query1="SELECT * FROM `products` WHERE `division`='$f_usr_div' ORDER BY `pname` UNION  SELECT `stock_close` FROM `stockiest_entry` WHERE `user_id`='$user_id' AND `stockiest_id`='$stckst_id' AND `month`='$f_month' AND `user_div`='$title_div' AND `fiscal_year`='$st_year'";
		$result1=mysql_query($query1);
		$i=0;
		while($a_row=mysql_fetch_array($result1))  // line 89
			{
                            global $i;
					$i++;
				$db_id=$a_row['id'];
				$db_pname=$a_row['pname'];
				$db_pcode=$a_row['pcode'];
				$db_packing=$a_row['packing'];
				$db_type=$a_row['ptype'];
				$db_unit=$a_row['unit'];
				$db_stock_close=$a_row['stock_close'];

				print "$db_id, $db_pname, $db_pcode , $db_packing, $db_type, $db_unit, $db_stock_close";

 

 

i got error.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /domains/55373/web/ipharma/form_header_final.php on line 89

 

Link to comment
https://forums.phpfreaks.com/topic/185791-mysql-union-warning-mysql_fetch_array/
Share on other sites

<?php
		$i = 0;
		$query1="SELECT * FROM `products` WHERE `division`='$f_usr_div' ORDER BY `pname` UNION  SELECT `stock_close` FROM `stockiest_entry` WHERE `user_id`='$user_id' AND `stockiest_id`='$stckst_id' AND `month`='$f_month' AND `user_div`='$title_div' AND `fiscal_year`='$st_year'";
		$result1=mysql_query($query1);
		$i=0;
		while($a_row=mysql_fetch_array($result1))  // line 89
			{
                            global $i;
					$i++;
				$db_id=$a_row['id'];
				$db_pname=$a_row['pname'];
				$db_pcode=$a_row['pcode'];
				$db_packing=$a_row['packing'];
				$db_type=$a_row['ptype'];
				$db_unit=$a_row['unit'];
				$db_stock_close=$a_row['stock_close'];

				print "$db_id, $db_pname, $db_pcode , $db_packing, $db_type, $db_unit, $db_stock_close";

 

 

i got error.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /domains/55373/web/ipharma/form_header_final.php on line 89

 

 

 

Execute MySql Error: Incorrect usage of UNION and ORDER BY

 

what is wrong with my codin.. please any one help me out..!

 

 

 

From my experience, you can not order the individual statements that constitute the UNION.

 

select * from table1
order by col1 <-- BAD (and pointless anyways)
union
select * from table2
order by col1 <-- Applies to entire result set, meaning all statements in the union

 

Someone correct me if I'm wrong please.

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.