-1

I now am getting this in my error log after fixing another problem. I've looked over everything on stackoverflow and all I come come up with is to get it to display an error, problem is I can't find where the error displays, so I can't troubleshoot it that way. Can anyone help give me some guidance? I'm not trying to do a duplicate, I'm really just trying to understand what is going on, sorry if this is misplaced (and if it is please let me know!).

This is the error:

[Wed Mar 27 01:36:41 2013] [error] PHP Warning:  mysql_fetch_array() expects parameter 1 to be resource, boolean given in /nas/wp/www/cluster-1434/XXXXXXX/wp-content/themes/mytheme/functions.php on line 574
[Wed Mar 27 01:36:14 2013] [error] PHP Warning:  mysql_fetch_array() expects parameter 1 to be resource, boolean given in /nas/wp/www/staging/XXXXXXX/wp-content/themes/mytheme/functions.php on line 572

This is line 572:

$ll = mysql_fetch_array($getLL);

This is line 574:

$cou = mysql_fetch_array($getCount);

Here is the code:

<?php
$con = conDB();
$x = 0;
//if ( false === ( $zip = get_transient( 'distinct_zips' ) ) ) {
$getZips = mysql_query("SELECT Distinct(meta_value) FROM wp_postmeta WHERE meta_key='_gmap_zip'",$con);
//$zip = mysql_fetch_array($getZips);
//  set_transient('distinct_zips', $zip, 60*5);
//}
while($zip = mysql_fetch_array($getZips)){
$getLL = mysql_query("SELECT * FROM zipcodes WHERE zip=".$zip['meta_value'],$con);
$ll = mysql_fetch_array($getLL);
$getCount = mysql_query("SELECT Count(*) FROM wp_postmeta WHERE meta_key='_gmap_zip' AND meta_value=".$zip['meta_value'],$con);
$cou = mysql_fetch_array($getCount);
$zipvalue = $zip['meta_value'];
$getNewest = mysql_query('SELECT * FROM wp_postmeta WHERE meta_key="_gmap_zip" AND meta_value="'.$zipvalue.'" LIMIT 5',$con);
if(strlen($ll['lat'])){
?>

Thanks in advance for all your help!

michaelrmcneill
  • 1,161
  • 1
  • 10
  • 23

3 Answers3

0

The queries:

$getLL = mysql_query("SELECT * FROM zipcodes WHERE zip=".$zip['meta_value'],$con);
$getCount = mysql_query("SELECT Count(*) FROM wp_postmeta WHERE meta_key='_gmap_zip' AND meta_value=".$zip['meta_value'],$con);

are failing returning false, leading to those two warnings.

As a general rule of thumb you should always check for errors when dealing with queries. You can do that by running:

if (!empty(mysql_error())) // error
Shoe
  • 72,892
  • 33
  • 161
  • 264
  • I understand that it is returning false, but how should I go about fixing that issue, especially since I cannot see the error? – michaelrmcneill Mar 27 '13 at 04:26
  • @michaelrmcneill, you can see the error by writing `var_dump(mysql_error())`. – Shoe Mar 27 '13 at 04:27
  • after adding that, my error log stops reporting everything related to this...Does that mean there isn't a problem? Or does that mean it is reporting it somewhere else? – michaelrmcneill Mar 27 '13 at 04:52
0
try var_dump($getLL)

It seems that it is returning false, because of any error in mysql_query() execution. Please always try to double check returning answer from mysql function before passing it to another function.

while($zip = mysql_fetch_array($getZips)){
$getLL = mysql_query("SELECT * FROM zipcodes WHERE zip=".$zip['meta_value'],$con);
if($getLL == false)
{
    echo mysql_error();
    exit;
}
$ll = mysql_fetch_array($getLL);
$getCount = mysql_query("SELECT Count(*) FROM wp_postmeta WHERE meta_key='_gmap_zip' AND meta_value=".$zip['meta_value'],$con);
$cou = mysql_fetch_array($getCount);
$zipvalue = $zip['meta_value'];
$getNewest = mysql_query('SELECT * FROM wp_postmeta WHERE meta_key="_gmap_zip" AND meta_value="'.$zipvalue.'" LIMIT 5',$con);
Maulik Vora
  • 2,463
  • 5
  • 27
  • 48
0

Please use below code after $getLL = mysql_query(...

if (!$getLL) { 
    die('Invalid query getLL: ' . mysql_error());
}

and also below code after $getCount = mysql_query(...

if (!$getCount) { 
    die('Invalid query getCount: ' . mysql_error());
}
Amir
  • 4,049
  • 4
  • 15
  • 26