Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

MySQL Advise Please...


carlost

Recommended Posts

Hello,

 

I have little to no MySQL knowledge, but I'm trying anyways!

 

What I am trying to do is make a query in the checkout_shipping.php file/page, which will determine the setting (true = 1 or false = 0) of a newly made column (products_skip_shipping) I have inserted into the products TABLE.

 

This is so I can then make an "if" statement to determine a redirection or not.

 

I've come up with the code below by looking at other code. However, it doesn't work!!! Seems like it might, but nope!

 

$products_skip_shipping_query = tep_db_query("select products_skip_shipping from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
$products_skip_shipping = tep_db_fetch_array($products_skip_shipping_query);
$products_skip_shipping_array[] = $products_skip_shipping['products_skip_shipping'];

if (in_array("1", $products_skip_shipping_array) && !in_array("0", $products_skip_shipping_array)) {
$products_skip_shipping = true;
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}

 

Sure would appreciate it if someone could clue me in some, maybe point me in the right direction!

 

Regards,

 

Carlos

Link to comment
Share on other sites

carlost,

 

Need to add...

 

$products_skip_shipping_fetch = tep_db_fetch_array $products_skip_shipping_query);

if ($products_skip_shipping_fetch ['?????'] == ????) {

 

 

}

 

Need to put this after your query and the ['?????'] goes your db field

 

I hope this help

Roman

dittone.com

Link to comment
Share on other sites

Hi Roman!

 

Thanks for replying!

 

I am not real clear exactly what you mean. I have tried several versions of the code you wrote. Below is the last try I did:

$products_skip_shipping_query = tep_db_query("select products_skip_shipping from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
$products_skip_shipping = tep_db_fetch_array($products_skip_shipping_query);
$products_skip_shipping_array[] = $products_skip_shipping['products_skip_shipping'];

$products_skip_shipping_fetch = tep_db_fetch_array($products_skip_shipping_query);
if ($products_skip_shipping_fetch ['products_skip_shipping'] == 1) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}

 

It doesn't work though.

 

Is this what you meant anyways?

 

Carlos

Link to comment
Share on other sites

carlost

Your close...The function tep_db_fetch_array stores table into varable

$products_skip_shipping_fetch thus the query that you did should be

followed with this.

 

$products_skip_shipping_fetch = tep_db_fetch_array($products_skip_shipping_query);

 

Look at the code for the functions tep_db_query and tep_db_fetch_array

This is os code...If you want to see actual examples scan the oscommerce modules for tep_db_query and you will see examples of this....

I hope this helps

Roman

 

 

Then as I have indicated with this code

if ($products_skip_shipping_fetch ['?????'] == ????) {

 

 

}

 

Allows you to evalute the table elements in the table($products_skip_shipping_fetch ['?????']

 

where this ????? in '?????'] you would put the table element name.

This == ????? is where you have your constant like '1'

Link to comment
Share on other sites

Hello Roman,

 

Thank you again for taking the time to help me, and especially for explaining it some.

 

I tried the following ways:

$products_skip_shipping_query = tep_db_query("select products_skip_shipping from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
$products_skip_shipping_fetch = tep_db_fetch_array($products_skip_shipping_query);
$products_skip_shipping_array[] = $products_skip_shipping['products_skip_shipping'];

if ($products_skip_shipping_fetch ['products_skip_shipping'] == 1) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}

and

$products_skip_shipping_query = tep_db_query("select products_skip_shipping from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
$products_skip_shipping_fetch = tep_db_fetch_array($products_skip_shipping_query);

if ($products_skip_shipping_fetch ['products_skip_shipping'] == 1) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}

Neither works.

 

I will keep trying.

 

I like your WebSite, by the way.

 

Thanks again.

 

Regards,

 

Carlos

Link to comment
Share on other sites

carlost,

the second bit of code looks better....try this bit of code and let us see what is located in this field..

 

$products_skip_shipping_query = tep_db_query("select products_skip_shipping from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

$products_skip_shipping_fetch = tep_db_fetch_array

($products_skip_shipping_query);

 

 

echo 'show products skip shipping '.$products_skip_shipping_fetch

['products_skip_shipping'];

 

if ($products_skip_shipping_fetch ['products_skip_shipping'] == 1) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));

}

 

The echo will display what is found in this field

 

 

 

 

Here is some code I copied from a program to show what I mean

 

 

 

$customer_info_query = tep_db_query("select customers_id from " . TABLE_ORDERS . " where orders_id = '". (int)$HTTP_GET_VARS['order_id'] . "'");

$customer_info = tep_db_fetch_array($customer_info_query);

if ($customer_info['customers_id'] != $customer_id) {

tep_redirect(tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));

}

 

 

Roman

Link to comment
Share on other sites

Awful generous of you to keep trying Ramon... Thanks.

 

Doesn't work.

 

I have a lot of files/pages that I have been able to figure out how to make an "if this, do that, else..." statement work (by looking at other code... lots of other code usually!).

 

For some reason the pages of the checkout process, and includes/application_top.php, have been especially difficult. It may be because my oscommerce application is very heavily modified.

 

I have had some success with checkout_payment.php, and checkout_confirmation.php, as well as product_info.php, and shopping_cart.php (making statements according to the product id) but so far none with checkout_shipping.php, checkout_success.php, and includes/application_top.php - all of which I need to complete my task.

 

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

 

I have found some code from a contribution that looks like it has some potential.

 

I'll just keep on plugging away at it.

 

Again, thanks again.

 

Regards,

 

Carlos

Link to comment
Share on other sites

Hey Roman!

 

I figured it was, only I didn't know how to take advantage of it!

 

Anyhow, I got it to work finally, messing around with this code I mentioned above, from a contribution. It seems like a whole lot of code for such a small function, and I'm guessing there's probably a more efficient way to go about it, but it works!

 

I messed around too, with using some of the same statements, with the codes you suggested because it is much less, but nothing worked this way.

 

Here's the code that seems to work, in case you're curious, and in case it toots a horn for someone else:

 

// <!-- Skip Shipping -->
 $check_skip_shipping_basket_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
 while ($check_skip_shipping_basket = tep_db_fetch_array($check_skip_shipping_basket_query)) {
$check_skip_shipping_query = tep_db_query("select products_skip_shipping from " . TABLE_PRODUCTS . " where products_id = '" . (int)$check_skip_shipping_basket['products_id'] . "'");
$check_skip_shipping = tep_db_fetch_array($check_skip_shipping_query);
$check_skip_shipping_array[] = $check_skip_shipping['products_skip_shipping'];
 }
 if (in_array("1", $check_skip_shipping_array) && !in_array("0", $check_skip_shipping_array)) {
$sendto = true;
// <!-- /Skip Shipping -->

  if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
  $shipping = false;
  $sendto = false;
  tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
 }

$total_weight = $cart->show_weight();
$total_count = $cart->count_contents();

I included some of the original checkout_shipping.php code so it's clear to someone else where it is placed.

 

Thanks again for all your time Roman, and for your generosity!

 

Regards,

 

Carlos

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...