473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

what is wrong with this piece of code

Hi everyone, I am new to php. I am using a piece of code which is
testing if a certain variable is <=0. and the code is written as
follows:

$lc_align = 'center';
if ($listing['products_quantity']<=0) {
$lc_text = tep_image_button('button_buy_now_na.gif',
IMAGE_BUTTON_BUY_NOW_NA) . '&nbsp;';
} else {
$lc_text = '<a href="' . tep_href_link(basename($PHP_SELF),
tep_get_all_get_params(array('action')) .
'action=buy_now&products_id=' . $listing['products_id']) . '">' .
tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) .
'</a>&nbsp;';
}
break;
}

The problem I am facing is that the this code returns all result to be
true ie. <=0 even though most of the variable are greater than 1. Is
the test wrong?
Or can I change the syntax and how do I do that

Any suggestion are welcomed.

Thanks
Jul 17 '05 #1
5 1840
Fendi Baba wrote:
Hi everyone, I am new to php.
Start *all* your scripts with

error_reporting(E_ALL);
ini_set('display_errors', '1');

This will make php report everything that may be wrong with your code.
I am using a piece of code which is
testing if a certain variable is <=0. and the code is written as
follows:

$lc_align = 'center';
if ($listing['products_quantity']<=0) { [snip] The problem I am facing is that the this code returns all result to be
true ie. <=0 even though most of the variable are greater than 1. Is
the test wrong?
Or can I change the syntax and how do I do that

Any suggestion are welcomed.

Try

var_dump($listing['products_quantity']);

This will tell you exactly what that variable holds.
Any value that php cannot convert to a numeric value is taken as 0
(zero) and, if that is your case, all comparisons will return true.

--
mail sent to my From: address is publicly readable at www.mailinator.net
I probably will never read it (possibly some one else will).
Jul 17 '05 #2
ef*****@epitome.com.sg (Fendi Baba) wrote in
news:c9**************************@posting.google.c om:
Hi everyone, I am new to php. I am using a piece of code which is
testing if a certain variable is <=0. and the code is written as
follows:

$lc_align = 'center';
if ($listing['products_quantity']<=0) {
$lc_text = tep_image_button('button_buy_now_na.gif',
IMAGE_BUTTON_BUY_NOW_NA) . '&nbsp;';
} else {
$lc_text = '<a href="' . tep_href_link(basename($PHP_SELF),
tep_get_all_get_params(array('action')) .
'action=buy_now&products_id=' . $listing['products_id']) . '">' .
tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) .
'</a>&nbsp;';
}
break;
}

The problem I am facing is that the this code returns all result to be
true ie. <=0 even though most of the variable are greater than 1. Is
the test wrong?
Or can I change the syntax and how do I do that

Any suggestion are welcomed.

Thanks


$listing['products_quantity'] is only one variable in an array.
Jul 17 '05 #3
> if ($listing['products_quantity']<=0) {

1. make sure $listing is an array:
is_array($listing);

2. make sure $listing has values:
!empty($listing);

3. double check the values to make sure they are not empty:
print_r($listing);
Jul 17 '05 #4

On Fri, 12 Nov 2004 07:54:16 -0800, Fendi
Baba wrote:
Hi everyone, I am new to php. I am using a piece of code which is
testing if a certain variable is <=0. and the code is written as
follows:

$lc_align = 'center';
if ($listing['products_quantity']<=0) {


First, start with the assumption that there's nothing wrong with PHP.

This leads you to the conclusion that most of the products_quanity are <=
0. Which may mean that the listing array is getting initialized wrong, or
some other upstream problem.

You can prove this to yourself with a simple print statement in the loop.
Or, if the code is being run on a webserver or some other place that makes
print statements inconvenient, print something to a log file.

When in doubt, print it out.

-- John

Jul 17 '05 #5
HI everyone. Thanks for the suggestion. I printed put the
var_dump($listing['products_quantity']) and it returned Null. And
this at least confirms that the piece of code is behaving properly.

I will be tracing the sql query and with your kind suggestions, I
think i should be ok to trace the errors.

Thanks you

Effendi

John Almberg <ja******@Identry.com> wrote in message news:<pa****************************@Identry.com>. ..
On Fri, 12 Nov 2004 07:54:16 -0800, Fendi
Baba wrote:
Hi everyone, I am new to php. I am using a piece of code which is
testing if a certain variable is <=0. and the code is written as
follows:

$lc_align = 'center';
if ($listing['products_quantity']<=0) {


First, start with the assumption that there's nothing wrong with PHP.

This leads you to the conclusion that most of the products_quanity are <=
0. Which may mean that the listing array is getting initialized wrong, or
some other upstream problem.

You can prove this to yourself with a simple print statement in the loop.
Or, if the code is being run on a webserver or some other place that makes
print statements inconvenient, print something to a log file.

When in doubt, print it out.

-- John

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: S.Shaigany | last post by:
Hi everybody, Please help me. I have a problem with my login page, which worked fine during the last one month. I have'nt made any changes in it. but from yesterday on, it seems that my PHP code...
10
by: Greener | last post by:
Hi, I need help badly. Can you do client-side programming instead of server-side to capture the Browser type info? If this is the case, what's wrong with the following? <script...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
1
by: Nobody | last post by:
I'm trying to write a class where I need to sort a list of TreeNode objects in a certain way. So I thought I'd use: List<ListNodeData> and then use the Sort method. I have the code working...
10
by: bob | last post by:
Hello, I use Microsoft Visual C++ .NET (version 7.1.3088) Sometimes (with big codes?) when I get a compile error and click on the error, the cursor is placed next to the wrong piece of code. The...
18
by: __PPS__ | last post by:
Hello, I'm a university student and I'm preparing for my final today. I'm reading course notes, I found completely strange piece of code. It makes me laugh, I think the teacher needs to prepare...
16
by: SirG | last post by:
I'm looking for an explanation of why one piece of code works and another does not. I have to warn you that this is the first piece of Javascript I've ever written, so if there is a better way or a...
10
by: Enkidu | last post by:
Beginner question, sorry! I am using indexers to access an array of StringBuilders in an instance of a class: Getting: value = board1; Setting: board1 = value1 ;
24
by: MU | last post by:
Hello I have some code that sets a dropdownlist control with a parameter from the querystring. However, when the querystring is empty, I get an error. Here is my code: Protected Sub...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.