SQL Table Error (table doesn't exist?)
Hello,
I'm trying to programme a '3 for 2' module and keep getting this error message:
Code:
1146 Table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist
in:
[ select products_id from products_3_for_2_flags where products_id = 882]
Is this trying to say I haven't got the table 'products_3_for_2_flags' in my database? Because, I have! Any ideas what's going wrong please? :)
Many thanks,
Gary:smile:
Re: SQL Table Error (table doesn't exist?)
I should also say that product id 882 is also in the table so not sure why it can't find it?
I tried flushing the table too but that didn't seem to work either.
Re: SQL Table Error (table doesn't exist?)
Quote:
Originally Posted by
plymgary1
keep getting this error message:
Table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist
< snip >
Is this trying to say I haven't got the table 'products_3_for_2_flags' in my database?
No. It is saying the table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist.
Quote:
Originally Posted by
plymgary1
Because, I have! Any ideas what's going wrong please? :)
The table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist. We have no way to know if table 'products_3_for_2_flags' exists or not. The error message says nothing about this table.
Cheers
Rod
Re: SQL Table Error (table doesn't exist?)
Quote:
Originally Posted by
RodG
No. It is saying the table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist.
The table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist. We have no way to know if table 'products_3_for_2_flags' exists or not. The error message says nothing about this table.
Cheers
Rod
Thanks for your reply. :)
Oh, I thought xkwies_handcrafteduk. was the name of the DB it was trying to access and products_3_for_2_flags was the table?
Am I wrong? If so, I'll have to find a way around it. :)
Re: SQL Table Error (table doesn't exist?)
Quote:
Originally Posted by
plymgary1
Thanks for your reply. :)
Oh, I thought xkwies_handcrafteduk. was the name of the DB it was trying to access and products_3_for_2_flags was the table?
Am I wrong? If so, I'll have to find a way around it. :)
Not entirely wrong, but the quotes make a huge difference in this case. In other words, 'xkwies_handcrafteduk.products_3_for_2_flags' (with quotes) is looking for a table of this name in the currently opened database.
If you remove the quotes it will indeed be looking for a table named 'products_3_for_2_flags' in the 'xkwies_handcrafteduk' database.
Does this make it clearer?
Cheers
Rod
Re: SQL Table Error (table doesn't exist?)
Quote:
Originally Posted by
plymgary1
Thanks for your reply. :)
Oh, I thought xkwies_handcrafteduk. was the name of the DB it was trying to access and products_3_for_2_flags was the table?
Am I wrong? If so, I'll have to find a way around it. :)
plymgary1, actually you are indeed correct.
RodG missed the fact that the SQL query gives away the fact that the query is indeed looking in the xkwies_handcrafteduk database for the table named products_3_for_2_flags.
So, instead, you probably have a prefix problem.
Re: SQL Table Error (table doesn't exist?)
Thanks for the replies. :)
I bet it's something really easy to fix but I just have no idea! Would someone mind taking a look at the code below from modules/order_total/ and see what the problem might be please?
Code:
<?php
class ot_3_for_2_discount_flags {
var $title, $output;
var $explanation;
function ot_3_for_2_discount_flags() {
$this->code = 'ot_3_for_2_discount_flags';
$this->title = MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_TITLE;
$this->description = MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_DESCRIPTION;
$this->sort_order = MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_SORT_ORDER;
$this->output = array();
}
function check_product($pid) {
global $db;
$sql_chk = " select products_id from products_3_for_2_flags where products_id = ". (int)$pid;
$rs_chk = $db->Execute($sql_chk);
if ($rs_chk->EOF) {
return false;
}
else {
return true;
}
}
function print_amount($amount) {
global $db, $order, $currencies;
return $currencies->format($amount, true, $order->info['currency'], $order->info['currency_value']);
}
function get_order_total() {
global $order;
$order_total_tax = $order->info['tax'];
$order_total = $order->info['total'];
$order_total -= $order->info['shipping_cost'];
$order_total -= $order->info['tax'];
$orderTotalFull = $order_total;
$order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax);
return $order_total;
}
function process() {
global $db, $order, $currencies;
$od_amount = $this->calculate_deductions();
if ($od_amount['total'] > 0) {
$order->info['total'] = $order->info['total'] - $od_amount['total'];
$this->title = '<a href="javascript:alert(\'' . $this->explanation . '\');">' . $this->title . '</a>';
$this->output[] = array('title' => $this->title . ':',
'text' => '-' . $currencies->format($od_amount['total'], true, $order->info['currency'], $order->info['currency_value']),
'value' => $od_amount['total']);
}
}
function calculate_deductions() {
global $db, $order, $currencies;
$od_amount = array();
$od_amount['tax'] = 0;
$products = $_SESSION['cart']->get_products();
$prod_list = array();
$prod_list_price = array();
$prod_list_back = array();
$all_items = 0;
$all_items_price = 0;
$disc_amount = 0;
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if ($this->check_product($products[$i]['id'])) {
$price = $products[$i]['final_price'];
$quantity = $products[$i]['quantity'];
//$disc_amount += $this->get_disc_amount($quantity, $price);
//$prod_list_back[$products[$i]['id']] = &$products[$i];
//$prod_list[$products[$i]['id']] += $quantity;
//$prod_list_price[$products[$i]['id']] += ($price * $quantity);
$all_items += $quantity;
//$all_items_price += ($price * $quantity);
}
}
$disc_amount += $this->get_disc_amount($all_items, $price);
$this->explanation = YOUR_CURRENT_3_FOR_2_DISCOUNT_FLAGS . "\\n" . "\\n";
$this->explanation .= "\\n\\n" . TOTAL_DISCOUNT . $this->print_amount($disc_amount);
$od_amount['total'] = round($disc_amount, 2);
return $od_amount;
}
function get_disc_amount($count,$price) {
$disc_amount = 0;
$new_count = $count - ($count%3);
// if (($count % 3) == 0) {
$disc_amount = ($new_count/3) * 3;
// }
return $disc_amount;
}
function pre_confirmation_check($order_total) {
$od_amount = $this->calculate_deductions();
return $od_amount['total'] + $od_amount['tax'];
}
function credit_selection() {
return $selection;
}
function collect_posts() {
}
function update_credit_account($i) {
}
function apply_credit() {
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function keys() {
return array('MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_STATUS', 'MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_SORT_ORDER');
}
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('© Gary<br /><div><a href=\"http://www.mywebsite.com\" target=\"_blank\">Website</a></div><br />This module is installed', 'MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_STATUS', 'true', '', '6', '1','zen_cfg_select_option(array(\'true\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_SORT_ORDER', '299', 'Sort order of display.', '6', '2', now())");
}
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
}
?>
The table products_3_for_2_flags is there too. Here's a screen cap :)
http://www.handcrafteduk.com/screen.jpg
Any idea? Please? :smile:
Re: SQL Table Error (table doesn't exist?)
Sounds like your configure.php is pointing to a different database than the one you're looking at in phpMyAdmin
Re: SQL Table Error (table doesn't exist?)
Quote:
Originally Posted by
DrByte
Sounds like your configure.php is pointing to a different database than the one you're looking at in phpMyAdmin
My thoughts exactly.
I can't think of any other explanation. Pity the top half of the screenshot provided was missing, else we'd know for sure :)
Cheers
Rod
Re: SQL Table Error (table doesn't exist?)
Sorry for the delay getting back.
I'm not sure the problem is with configure.php? There's no other connectivity problem with the db.
Here's a screenshot where you can see the table name. :)
[scr]http://www.handcrafteduk.com/screen2.jpg[/scr]