Jump to content

mysql UNION | warning mysql_fetch_array !!


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