Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

General PHP coding issue....


spannerman

Recommended Posts

Posted

Hi folks,

 

I'm trying to tweak the code of my site, working with the $products_id variable but what I'm trying aint working.

 

I have very heavily modded site, and now have the requirement to basically turn a mod off if the product id is greater than 10000.

 

What I'm trying is this. I have the original lines of code and the modded lines of code and am trying an if else statement to switch between them.

 

 if ($products_id <= 10001) {

Original code

} else {

Modified code
}

 

I've been searching the web as to why this simple enough looking code isn't doing what it should. The site is still working but I just get the original code when looking at products with an ID of over 10000.

 

The PHP manual talks about types in comparisons and I'm wondering if this is the problem.

 

How is the $products_id variable stored? Integer or String? Should I put it in another "holding" variable while I make the comparison?

 

I've tried wrapping the 10001 value in single quotes, double quotes & no quotes. I can output the $product_id variable to the screen as a number, but is that number an integer or a string or something else?

 

I'm on PHP 5.1.2 MySQL 5 and osC2.2 MS 2 if that's a consideration.

 

Very frustrating situation and all help much appreciated!

 

TIA

 

Simon

Posted

Try something like this and Please backup

 

<?php
 if ($products_id-> 1001) {
original code
}else{
modified code
}

 

The way you had the great to or equal was wrong this should work for you.

 

Eric

Posted

Yes, it's possible that there's some type incompatibility. Anyway, I guess it wouldn't hurt to convert the $products_id variable to int.

 

If I remember the PHP coding correctly (I've just began to study it!), this should do:

 if ( (int) $products_id <= 10001) {

Original code

} else {

Modified code
}

 

Hope it helps!! :)

Posted

Also, if the "<=" is right or not depends on what you want. If you want the original code to be executed for ID's smaller than 10001, then it's correct. If not, the original code is for the ID's greater than 10001, then you should change it to ">=".

 

Like this:

 

 if ( (int) $products_id =< 10001) {

Posted

Thanks for the input folks!

 

Bit late now but I'll try your suggestions tomorrow (later, since it's already Sunday!) and let you know.

Archived

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

×
×
  • Create New...