Author Topic: mysql UNION | warning mysql_fetch_array !!  (Read 1584 times)

0 Members and 1 Guest are viewing this topic.

Offline subash85Topic starter

  • Irregular
  • Posts: 19
  • Gender: Male
  • Versatile Design
    • View Profile
    • Subash Gurung
mysql UNION | warning mysql_fetch_array !!
« on: December 20, 2009, 01:04:38 PM »
Code: [Select]
<?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

Offline Buddski

  • Devotee
  • Posts: 1,231
  • Gender: Male
    • View Profile
    • Buddski Development
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #1 on: December 20, 2009, 01:08:29 PM »
It means your query has failed to execute..
Use mysql_error() to find out the error
"The problem with a UDP joke is that you have no idea if people got it."
--------------------------------
When posting an error that contains a line number, please show what that line actually contains.

Offline subash85Topic starter

  • Irregular
  • Posts: 19
  • Gender: Male
  • Versatile Design
    • View Profile
    • Subash Gurung
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #2 on: December 21, 2009, 05:02:20 AM »
Code: [Select]
<?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..!



Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,444
  • Gender: Male
    • View Profile
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #3 on: December 21, 2009, 01:20:25 PM »
Wrap your queries in parens.
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

Offline subash85Topic starter

  • Irregular
  • Posts: 19
  • Gender: Male
  • Versatile Design
    • View Profile
    • Subash Gurung
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #4 on: December 22, 2009, 09:54:42 PM »
how to do that i didnt get ya.... em juz newbie to php so need some example helpps..

Offline subash85Topic starter

  • Irregular
  • Posts: 19
  • Gender: Male
  • Versatile Design
    • View Profile
    • Subash Gurung
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #5 on: December 22, 2009, 10:27:52 PM »
please anyone can help me to solve my problem... thank you... i will so greatful to you all... and the phpfreaks.com family...

Offline roopurt18

  • Guru
  • Fanatic
  • *
  • Posts: 3,658
  • Gender: Male
  • le sigh
    • View Profile
    • rbredlau
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #6 on: December 22, 2009, 10:31:25 PM »
From my experience, you can not order the individual statements that constitute the UNION.

Code: [Select]
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.

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,444
  • Gender: Male
    • View Profile
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #7 on: December 27, 2009, 12:18:32 PM »
Write them as though they were sub-selects.
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

Offline subash85Topic starter

  • Irregular
  • Posts: 19
  • Gender: Male
  • Versatile Design
    • View Profile
    • Subash Gurung
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #8 on: February 24, 2010, 05:38:36 AM »
mysql_error(Resource id #10)

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,444
  • Gender: Male
    • View Profile
Re: mysql UNION | warning mysql_fetch_array !!
« Reply #9 on: February 24, 2010, 02:48:30 PM »
Great... what error, what query?
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.