473,394 Members | 1,709 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,394 software developers and data experts.

What is wrong with this if test?

OK, I am at a toral loss after having programmed for forty years.

Here are my results:

selHint_2=1
It is clear that for the second time through the loop ($i=1) that
$index=1 and $selHint_2=1, while for the first pass through ($i=0) $index=0
and $selHint=1. Yet, the " selected " comes up for the first time and not
for the second. It should be the other way around. Any clues?

Shelly
Here is the code:
$numHint_2 = 2;
$hint_2_Lookup = array(0, 1);
$hint_2 = array();
$hint_2[] = " Family member's name";
$hint_2[] = " Mothers maiden name";
$foo = ""; // put in for debugging only
$tmpHint2 = array();
$tmpHint2[] = '<td class="stdBold"' . $readonly . '>';
$tmpHint2[] = '<select name="hint_1" value="" >';
for ($i=0; $i<$numHint_2; $i++) {
$index = $hint_2_Lookup[$i];
if ($index == $selHint_2) {
$sel = " selected ";
} else {
$sel = "";
}
$tmpHint2[] = '<option value="' . $index . '"' . $sel . '>' .
$hint_2[$i] . '</option>';
// next line put in for debugging only
$foo .= 'index=' . $index . ' option value="' . $index . '"' .
$sel . $hint_2[$i]. "<br>";
}
$tmpHint2[] = '</select></td>';

$selHint_2 = $_SESSION['vmHint_2']; // put in for
debugging only
echo "selHint_2=" . $selHint_2 . "<br>"; // put in for
debugging only
echo implode("\n",$tmpHint2)."\n";
echo $foo; // put in for debugging only

index=0 option value="0" selected Family member's name
index=1 option value="1" Mothers maiden

Dec 29 '05 #1
6 1443
Oops, here is the output:

selHint_2=1 index=0 option value="0" selected Family member's name
index=1 option value="1" Mothers maiden

"Shelly" <sh************@asap-consult.com> wrote in message
news:Z5********************@comcast.com...
OK, I am at a toral loss after having programmed for forty years.

Here are my results:

selHint_2=1
It is clear that for the second time through the loop ($i=1) that
$index=1 and $selHint_2=1, while for the first pass through ($i=0)
$index=0 and $selHint=1. Yet, the " selected " comes up for the first
time and not for the second. It should be the other way around. Any
clues?

Shelly
Here is the code:
$numHint_2 = 2;
$hint_2_Lookup = array(0, 1);
$hint_2 = array();
$hint_2[] = " Family member's name";
$hint_2[] = " Mothers maiden name";
$foo = ""; // put in for debugging only
$tmpHint2 = array();
$tmpHint2[] = '<td class="stdBold"' . $readonly . '>';
$tmpHint2[] = '<select name="hint_1" value="" >';
for ($i=0; $i<$numHint_2; $i++) {
$index = $hint_2_Lookup[$i];
if ($index == $selHint_2) {
$sel = " selected ";
} else {
$sel = "";
}
$tmpHint2[] = '<option value="' . $index . '"' . $sel . '>' .
$hint_2[$i] . '</option>';
// next line put in for debugging only
$foo .= 'index=' . $index . ' option value="' . $index . '"'
. $sel . $hint_2[$i]. "<br>";
}
$tmpHint2[] = '</select></td>';

$selHint_2 = $_SESSION['vmHint_2']; // put in for
debugging only
echo "selHint_2=" . $selHint_2 . "<br>"; // put in for
debugging only
echo implode("\n",$tmpHint2)."\n";
echo $foo; // put in for debugging only

index=0 option value="0" selected Family member's name
index=1 option value="1" Mothers maiden


Dec 29 '05 #2
OK, I fixed it, but I know why it didn't work before.

The if test stuff was in an include file (that is bracketed by <?php ?>.
When I cut and pasted that code into inline code, it worked. The problem
was that the include file was at the beginning of the page, so the test was
before getting any values. Some times the stupid errors are the hardest to
find.

Shelly

"Shelly" <sh************@asap-consult.com> wrote in message
news:e8********************@comcast.com...
Oops, here is the output:

selHint_2=1 index=0 option value="0" selected Family member's name
index=1 option value="1" Mothers maiden

"Shelly" <sh************@asap-consult.com> wrote in message
news:Z5********************@comcast.com...
OK, I am at a toral loss after having programmed for forty years.

Here are my results:

selHint_2=1
It is clear that for the second time through the loop ($i=1) that
$index=1 and $selHint_2=1, while for the first pass through ($i=0)
$index=0 and $selHint=1. Yet, the " selected " comes up for the first
time and not for the second. It should be the other way around. Any
clues?

Shelly
Here is the code:
$numHint_2 = 2;
$hint_2_Lookup = array(0, 1);
$hint_2 = array();
$hint_2[] = " Family member's name";
$hint_2[] = " Mothers maiden name";
$foo = ""; // put in for debugging only
$tmpHint2 = array();
$tmpHint2[] = '<td class="stdBold"' . $readonly . '>';
$tmpHint2[] = '<select name="hint_1" value="" >';
for ($i=0; $i<$numHint_2; $i++) {
$index = $hint_2_Lookup[$i];
if ($index == $selHint_2) {
$sel = " selected ";
} else {
$sel = "";
}
$tmpHint2[] = '<option value="' . $index . '"' . $sel . '>'
. $hint_2[$i] . '</option>';
// next line put in for debugging only
$foo .= 'index=' . $index . ' option value="' . $index . '"'
. $sel . $hint_2[$i]. "<br>";
}
$tmpHint2[] = '</select></td>';

$selHint_2 = $_SESSION['vmHint_2']; // put in for
debugging only
echo "selHint_2=" . $selHint_2 . "<br>"; // put in for
debugging only
echo implode("\n",$tmpHint2)."\n";
echo $foo; // put in for debugging only

index=0 option value="0" selected Family member's name
index=1 option value="1" Mothers maiden



Dec 29 '05 #3
Shelly wrote:
OK, I am at a toral loss after having programmed for forty years.
Turn on error_reporting for all errors, warnings and notices.
.... maybe you'll notice some uninitialized variable.

Insert these two lines at the top of your script

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

<snip> for ($i=0; $i<$numHint_2; $i++) {
$index = $hint_2_Lookup[$i];
if ($index == $selHint_2) {
possible use of unassigned variable?
$sel = " selected ";
} else {
$sel = "";
}
$tmpHint2[] = '<option value="' . $index . '"' . $sel . '>' .
$hint_2[$i] . '</option>';
// next line put in for debugging only
$foo .= 'index=' . $index . ' option value="' . $index . '"' .
$sel . $hint_2[$i]. "<br>";
}
$tmpHint2[] = '</select></td>';

$selHint_2 = $_SESSION['vmHint_2']; // put in for
debugging only
You're assigning to $selHint_2 after you've used the variable in the
test above.
echo "selHint_2=" . $selHint_2 . "<br>"; // put in for
debugging only
echo implode("\n",$tmpHint2)."\n";
echo $foo; // put in for debugging only


Happy debugging :)

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Dec 29 '05 #4
Message-ID: <O8********************@comcast.com> from Shelly contained
the following:
Some times the stupid errors are the hardest to
find.


This seems to happen quite a bit. I suppose what happens is that you
work on something for ages and get totally bogged down and then, in
desperation, make a post to the group. Then, knowing you have to wait
for a reply, you put the problem to one side and relax. The relaxation
enables you to see the solution.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Dec 29 '05 #5
"Shelly" <sh************@asap-consult.com> wrote:

OK, I am at a toral loss after having programmed for forty years.


If you programmed for forty years, you must be tired. ;)
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Dec 30 '05 #6
"Shelly" <sh************@asap-consult.com> wrote in
news:O8********************@comcast.com:
Some times the
stupid errors are the hardest to find.

Shelly


Fact! Those stupid errors are always messing up *my* code. ;)
Try sprinkling a little Modula into a C program. That's why I like
PHP, handling C syntax or Perl if I goof on the last couple of
languages I've done much coding in. Of course, it's forgiving nature
can sometimes get us in trouble too.

--
Stan McCann "Uncle Pirate" http://stanmccann.us/pirate.html
Webmaster/Computer Center Manager, NMSU at Alamogordo
http://alamo.nmsu.edu/ There are 10 kinds of people.
Those that understand binary and those that don't.
Jan 2 '06 #7

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

Similar topics

10
by: siu02rk | last post by:
Hi all, I am trying to get an understanding of classes within PHP. What is wrong with this code: <html> <title> This is my test for creating a class </test> <body> <?php
2
by: MLH | last post by:
DELETE test.name FROM test WHERE (((test.name) Like "o*")); I use MS Access. The above SQL is OK with Access, but not with MySQL. Other than the semicolon at the end of the phrase, what's wrong...
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...
5
by: Ronald Fischer | last post by:
I have a server-side JavaScript function returning a string. I would like to test wheather or not the string contains the following pattern: - an equal sign, - followed by one or more characters...
1
by: PengYu.UT | last post by:
I forward declared the class test. But I still get some error. Would you please help me to find out what is wrong with this program? Peng //#include <utility> #include <iostream> //using...
1
by: cylin | last post by:
Dear all, I am a newbie using lex and yacc. I really don't know what's wrong with my code, because the output is not what I want. My yacc rules don't match, and yylex seems just read only one...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
6
by: paul.anderson | last post by:
This code doesn't work - the first retrieval of t2 returns valid data, the subsequent do not. Please help!!! int main(int argc, char* argc){ struct Test{ int i; int j; intk; int l; }
15
by: > Adrian | last post by:
void establishAddress(out string address_line) { // do something } string address_to_print = new string; address_to_print = establishAddress(out address_line); Apart from the fact that I...
5
by: Jeff | last post by:
ASP.NET 2.0 This code crashes. It generate this error: Value cannot be null. Parameter name: type I've created some custom web.config settings and this crash is related to accessing theme...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.