Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Could someone take a quick look at my query


Guest

Recommended Posts

Posted

I'm getting a syntax error and I think I've been looking at it too long, as I don't see it. This query is to display a list of all the "attendees" to a particular event capture by the "GET VARS" product_id and ordered by gender. (Customers = attendees and Products = Events)

 

Thanks in advance

 

<?php

if ($HTTP_GET_VARS['page'] > 1) $rows = $HTTP_GET_VARS['page'] * MAX_DISPLAY_ATTENDEE - MAX_DISPLAY_ATTENDEE;

$pID = 0;

if (isset($HTTP_GET_VARS['pID']))

{

$pID = $HTTP_GET_VARS['pID'];

}

$attendee_query_raw = "select c.customers_firstname, c.customers_id, c.customers_gender, op.products_id, from " . TABLE_CUSTOMERS . " c, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o where c.customers_id = o.customers_id and o.orders_id = op.orders_id and op.products_id = " . $pID . " group by c.customers_firstname order by c.customers_gender";

$attendee_split = new splitPageResults($HTTP_GET_VARS['pID'], MAX_DISPLAY_ATTENDEE, $attendee_query_raw, $attendee_query_numrows);

$attendee_query_numrows = tep_db_query("select customers_id from " . TABLE_ORDERS . " group by customers_id");

$attendee_query_numrows = tep_db_num_rows($attendee_query_numrows);

 

$attendee_query = tep_db_query($attendee_query_raw);

while ($attendee = tep_db_fetch_array($attendee_query)) {

$rows++;

 

if (strlen($rows) < 2) {

$rows = '0' . $rows;

}

?>

Posted

Please, Please, look at my query in my first post above. I really want to go home tonight :cry:

 

Thanks

Posted

Hi there,

 

the conditional part of your DB statement

 

c.customers_id = o.customers_id and o.orders_id = op.orders_id and op.products_id = " . $pID . "

I believe is in incorrent form, easy thing to miss...

 

 

it should be like this

 

c.customers_id = 'o.customers_id' and o.orders_id = 'op.orders_id' and op.products_id = ' " . $pID . " '

 

(and yes the curly bracket too....)

 

cheers and HTH

Peter McGrath

-----------------------------

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Posted

thanks to both of you. I'm still a newbie, so sometimes things that are obvious to you "old" pros are missed by us less fortunates.

 

I'll watch those pesky "curly brakets" more closely in the future and hopefully I can someday be a good as you guys. :)

 

Thanks again,

 

Ruth in AZ

Posted

I made the changes as you suggested, but I'm still getting an error. I know the query its self is valid as I ran it direct against the db, but I just keep getting an SQL Syntax error message within the app. Here's the revised code:

 

$attendee_query_raw = "SELECT c.customers_firstname, c.customers_id, c.customers_gender, op.products_id FROM " . TABLE_CUSTOMERS . " c, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o WHERE c.customers_id = 'o.customers_id' AND o.orders_id = 'op.orders_id' and op.products_id = '" . $pID . "' group by c.customers_firstname order by c.customers_gender";

$attendee_split = new splitPageResults($HTTP_GET_VARS['pID'], MAX_DISPLAY_ATTENDEE, $attendee_query_raw, $attendee_query_numrows);

$attendee_query_numrows = tep_db_query("select customers_id from " . TABLE_ORDERS . " group by customers_id");

$attendee_query_numrows = tep_db_num_rows($attendee_query_numrows);

 

$attendee_query = tep_db_query($attendee_query_raw);

while ($attendee = tep_db_fetch_array($attendee_query)) {

$rows++;

 

}

if (strlen($rows) < 2) {

$rows = '0' . $rows;

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...