Zen Cart Logo
Forums / General Questions / Whats wrong with this query? Fresh eyes needed ;)

Whats wrong with this query? Fresh eyes needed ;)

Locked

Views: 1,194

Results 1 to 10 of 10
This thread is locked. New replies are disabled.
9 Sep 2006, 5:03 PM
#1
reesy avatar

reesy

Totally Zenned

Join Date:
Mar 2005
Posts:
535
Plugin Contributions:
3

Whats wrong with this query? Fresh eyes needed ;)

Theres only so long you can go staring at the same 2 line query wondering why it doesnt work before it drives you crazy.:sleepy:

$points_query = $db->Execute("SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' AND customers_points_expires > CURDATE() LIMIT 1");

Can anyone with less tired eyes than me suggest a solution as to why this is causing a Call to a member function on a non-object error.:lookaroun

Thanks muchly.

9 Sep 2006, 6:08 PM
#2
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Whats wrong with this query? Fresh eyes needed ;)

I think you are trying to use this line of code inside a function, but forgot to make $db global.

like:

global $db;
10 Sep 2006, 2:20 PM
#3
reesy avatar

reesy

Totally Zenned

Join Date:
Mar 2005
Posts:
535
Plugin Contributions:
3

Re: Whats wrong with this query? Fresh eyes needed ;)

Thanks for that.
I now get an error
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Object' at line 1
in:
[Object]

if (zen_not_null(POINTS_AUTO_EXPIRES)){
	global $db;
	  $points_query = $db->Execute("SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' AND customers_points_expires > CURDATE() LIMIT 1");
    } else {
	  $points_query = $db->Execute("SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' LIMIT 1");
    }
    $points = $db->Execute($points_query);

    return $points['customers_shopping_points'];
  }
10 Sep 2006, 2:22 PM
#4
merlinpa1969 avatar

merlinpa1969

Totally Zenned

Join Date:
Mar 2004
Posts:
13,031
Plugin Contributions:
4

Re: Whats wrong with this query? Fresh eyes needed ;)

try using the global Outside the if statement

10 Sep 2006, 2:34 PM
#5
reesy avatar

reesy

Totally Zenned

Join Date:
Mar 2005
Posts:
535
Plugin Contributions:
3

Re: Whats wrong with this query? Fresh eyes needed ;)

Hi Merlin,
I tried that first time around adding it to the top of the file.
If I do that I get the same fatal error
Fatal error: Call to a member function on a non-object

if (zen_not_null(POINTS_AUTO_EXPIRES)){
	  $points_query = $db->Execute("SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' AND customers_points_expires > CURDATE() LIMIT 1");
    } else {
	  $points_query = $db->Execute("SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' LIMIT 1");
    }

Feeling much fresher today but cant figure this out for the life of me :down:

10 Sep 2006, 4:26 PM
#6
reesy avatar

reesy

Totally Zenned

Join Date:
Mar 2005
Posts:
535
Plugin Contributions:
3

Re: Whats wrong with this query? Fresh eyes needed ;)

ahhhhh the wonders of coca cola ;)
Ive figured it out, theres not meant to be any _query on any of the queries so...

if (zen_not_null(POINTS_AUTO_EXPIRES)){
$points_query = $db->Execute("SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' AND customers_points_expires > CURDATE() LIMIT 1");
} else {
$points_query = $db->Execute("SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' LIMIT 1");
}

Isnt meant to be there.
:smile:

10 Sep 2006, 4:39 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Whats wrong with this query? Fresh eyes needed ;)

Note: this line ...

return $points['customers_shopping_points'];

Might result in a better answer if you use:

return $points->fields['customers_shopping_points'];
10 Sep 2006, 5:02 PM
#8
reesy avatar

reesy

Totally Zenned

Join Date:
Mar 2005
Posts:
535
Plugin Contributions:
3

Re: Whats wrong with this query? Fresh eyes needed ;)

Thanks to Ajeh for the pointer...
In the end my cola power cotton wool fueled head decided to check how another file does this and finally came up with the following ...

    if (zen_not_null(POINTS_AUTO_EXPIRES)){
	global $db;
	  $points_query = "SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' AND customers_points_expires > CURDATE() LIMIT 1";
    } else {
	  $points_query = "SELECT customers_shopping_points FROM " . TABLE_CUSTOMERS . " WHERE customers_id = '" . (int)$id . "' LIMIT 1";
    }
    $points = $db->Execute("$points_query");

    return $points->fields['customers_shopping_points'];
  }
11 Sep 2006, 1:50 AM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Whats wrong with this query? Fresh eyes needed ;)

NOTE: if this is in a function ...

The standard way to do this is to have:

function my_function_name() {
  global $whoever, $whoever2, $whoever_etc;
// code stuff here
}
11 Sep 2006, 4:15 AM
#10
reesy avatar

reesy

Totally Zenned

Join Date:
Mar 2005
Posts:
535
Plugin Contributions:
3

Re: Whats wrong with this query? Fresh eyes needed ;)

Thank you Linda! :hug: