6 Replies - 6772 Views - Last Post: 13 September 2011 - 12:43 PM Rate Topic: -----

#1 GreenSquid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 11

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

Posted 12 September 2011 - 12:21 PM

Hello,

I am receiving these warnings (3 total) whenever I run this page "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL..."

I have searched google and dream.in.code forums for people experiencing similar problems/warnings, and have had no success trying their resolutions/troubleshooting recommendations.

(I have made sure it is connection to the database, and that the MySQL querys work)

Here is the code I am having issues with:

<? 
require_once('_config.php');

$main_string = "SELECT * FROM place_db WHERE place_status = 'ACTIVE'";
$main_results = mysql_query($main_string);

while ($main_row=mysql_fetch_array($main_results){
	$week_place_amount = "SELECT SUM(events_amount) AS place_week_total FROM events_db WHERE events_place = '".$main_row['place_name']."' AND (events_status = 'OCCURRED' OR events_status = 'PENDING INVOICE' OR events_status = 'INVOICED') AND events_date BETWEEN '".$start_date."' AND '".$end_date."'";
	$place_events_week = mysql_query($week_place_amount);
        //error highlights this line
	$place_events_count_week = mysql_fetch_array($place_events_week);
				
	$month_place_amount = "SELECT SUM(events_amount) AS place_month_total FROM events_db WHERE events_place = '".$main_row['place_name']."' AND events_month = '".$month."' AND (events_status = 'OCCURRED' OR events_status = 'PENDING INVOICE' OR events_status = 'INVOICED')";
	$place_events_month = mysql_query($month_place_amount);
        //this line
	$place_events_count_month = mysql_fetch_array($place_events_month);
				
	$year_place_amount = "SELECT SUM(events_amount) AS place_year_total FROM events_db WHERE events_place = '".	$main_row['place_name']."' AND events_year = '".$year."' AND (events_status = 'OCCURRED' OR events_status = 'PENDING INVOICE' OR events_status = 'INVOICED')";
	$place_events_year = mysql_query($year_place_amount);
        //and this line
	$place_events_count_year = mysql_fetch_array($place_events_year);

	echo "<tr><td style=\"text-align:left;\">&nbsp;".$main_row['place_name']."</td><td></td><td style=\"text align:right;\">$".number_format($place_events_count_week['place_week_total'],2)."</td><td style=\"text-align:right;\">$".number_format($place_events_count_month['place_month_total'],2)."</td><td style=\"text-align:right;\">$".number_format($place_events_count_year['place_year_total'],2)."</td></tr>";
}
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,361
  • Joined: 27-December 08

Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

Posted 12 September 2011 - 12:31 PM

Add an or die(mysql_error()) clause after your mysql_query() statements to see if there are any problems with the queries. This error means that a valid result set is not returned.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5163
  • View blog
  • Posts: 26,830
  • Joined: 10-May 07

Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

Posted 12 September 2011 - 12:38 PM

Quote

while ($main_row=mysql_fetch_array($main_results){

Verify that $main_row has a value before using it.

Your code assumes that it has a value, & when it does not php pukes.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6032
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

Posted 12 September 2011 - 01:04 PM

Read #3 in the PHP FAQs.

If I had my way, as soon as you started typing the title you'd be brought to this page.
Was This Post Helpful? 0
  • +
  • -

#5 GreenSquid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 11

Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

Posted 13 September 2011 - 07:46 AM

View PostJackOfAllTrades, on 12 September 2011 - 01:04 PM, said:

Read #3 in the PHP FAQs.

If I had my way, as soon as you started typing the title you'd be brought to this page.


Thanks, JackOfAllTrades, for being genteel. As I'd mentioned in my original post: "I have searched ... dream.in.code forums for ... similar problems/warnings, and have had no success trying their resolutions/troubleshooting recommendations." My hope was to have a fresh look at my code for errors / anymore recommendations for a resolution. (I suspected it was a simple solution)

Many thanks macosxnerd101 and no2pencil. It was no2pencil's advice to verify my main_row output that lead me to finding the error:

One of the values from $main_row['place_name'] contained a possession apostrophe (id est Joe's Place). This was the cause for my php puking.

Problem solved. Many Thanks.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5163
  • View blog
  • Posts: 26,830
  • Joined: 10-May 07

Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

Posted 13 September 2011 - 11:59 AM

View PostGreenSquid, on 13 September 2011 - 10:46 AM, said:

Thanks, JackOfAllTrades, for being genteel. As I'd mentioned in my original post: "I have searched ... dream.in.code forums for ... similar problems/warnings, and have had no success trying their resolutions/troubleshooting recommendations." My hope was to have a fresh look at my code for errors / anymore recommendations for a resolution. (I suspected it was a simple solution)

It truly is the #1 asked question in PHP. I'm not suggesting that it gets asked a lot, I'm saying it would be odd for this question not to be posted/asked multiple times per month!
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3476
  • View blog
  • Posts: 10,012
  • Joined: 08-June 10

Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

Posted 13 September 2011 - 12:43 PM

View PostGreenSquid, on 13 September 2011 - 04:46 PM, said:

One of the values from $main_row['place_name'] contained a possession apostrophe (id est Joe's Place). This was the cause for my php puking.

there is an easy (though advanced) way to overcome where no input will interfere with your query (called Prepared Statement) but that’s for later.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1