473,698 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_quant ity']<=0) {
$lc_text = tep_image_butto n('button_buy_n ow_na.gif',
IMAGE_BUTTON_BU Y_NOW_NA) . '&nbsp;';
} else {
$lc_text = '<a href="' . tep_href_link(b asename($PHP_SE LF),
tep_get_all_get _params(array(' action')) .
'action=buy_now &products_id =' . $listing['products_id']) . '">' .
tep_image_butto n('button_buy_n ow.gif', IMAGE_BUTTON_BU Y_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 1859
Fendi Baba wrote:
Hi everyone, I am new to php.
Start *all* your scripts with

error_reporting (E_ALL);
ini_set('displa y_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_quant ity']<=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($listi ng['products_quant ity']);

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.goo gle.com:
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_quant ity']<=0) {
$lc_text = tep_image_butto n('button_buy_n ow_na.gif',
IMAGE_BUTTON_BU Y_NOW_NA) . '&nbsp;';
} else {
$lc_text = '<a href="' . tep_href_link(b asename($PHP_SE LF),
tep_get_all_get _params(array(' action')) .
'action=buy_now &products_id =' . $listing['products_id']) . '">' .
tep_image_butto n('button_buy_n ow.gif', IMAGE_BUTTON_BU Y_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_quant ity'] is only one variable in an array.
Jul 17 '05 #3
> if ($listing['products_quant ity']<=0) {

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

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

3. double check the values to make sure they are not empty:
print_r($listin g);
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_quant ity']<=0) {


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

This leads you to the conclusion that most of the products_quanit y 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($listi ng['products_quant ity']) 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******@Ident ry.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_quant ity']<=0) {


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

This leads you to the conclusion that most of the products_quanit y 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
2595
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 receives wrong POST variables. This is my HTML code piece which just produces login form: <form name="login" action="default.php" method="post"> UserName:<input type="text" name="username" size="15" maxlength="20"
10
3404
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 language="JavaScript"> function doWord(file) { if (navigator.userAgent.indexOf("MSIE")!=-1)
51
13363
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 wrong????? Function x select case z
1
1588
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 using SortedList class, but its too slow since it sorts each time you insert. But just by DECLARING the ListNodeData object, I get the infamous "exception has been
10
1636
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 line number in the error message and that of the cursor do match but the real error is somewhere else. The same I get when debugging my code, the piece of code the cursor is at is no way the code that is actually debugged. This is very frustating!...
18
2259
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 herself for this course. so I ask for your point of view. here's the piece of code: Memory management by client!! // Listing 9.4. Memory management by client rather than by server object
16
1906
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 simpler answer, by all means show me the light! What I'm trying to do is refresh the page at a timed interval ( actually redirect the page... ) and I have a simple piece of code I got from the net that works, but I need to modify it a little...
10
1926
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
3091
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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.