It seems so easy....
Moderator: General Moderators
- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
It seems so easy....
It seems so easy, but it simply doesn't work.
this is NEVER true:
IF ($itemArray[$i] == $itemValue) {
this is ALWAYS true:
IF ($itemArray[$i] = $itemValue) {
But, when I'm printing the values of the variables, it is "Mr" both times.
Why isn't the first comparison working as it should be?
Kind regards,
Antonie
this is NEVER true:
IF ($itemArray[$i] == $itemValue) {
this is ALWAYS true:
IF ($itemArray[$i] = $itemValue) {
But, when I'm printing the values of the variables, it is "Mr" both times.
Why isn't the first comparison working as it should be?
Kind regards,
Antonie
- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
Off course
Yeah, thanks Draco.
Those are the kind of advices I need
Let me rephrase the question:
How is it possible, that == isn't reacting, when echoing of both variables results in the same echo?
ECHO $itemArray[$i];
// -> Mr
ECHO $itemValue;
// -> Mr
Those are the kind of advices I need
Let me rephrase the question:
How is it possible, that == isn't reacting, when echoing of both variables results in the same echo?
ECHO $itemArray[$i];
// -> Mr
ECHO $itemValue;
// -> Mr
want to post your whole code (relevent code) with
Code: Select all
tags plz
I'll be more able to help you (if I can )- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
Code: Select all
<?php
// ....
// Creation of an array called $titel
// The array is like [Prof, Mr, Ir, Bac]
// ...
print("<SELECT class="selectBox" name="titel[]" SIZE="3" MULTIPLE>\n");
IF (count($titel) == 0) {
print(" <OPTION value="" SELECTED>Geen titel</OPTION>\n");
}
fillMultipleSelectList("Prof", $titel);
fillMultipleSelectList("Mr", $titel);
fillMultipleSelectList("Dr", $titel);
fillMultipleSelectList("Drs", $titel);
fillMultipleSelectList("Ir", $titel);
fillMultipleSelectList("Ing", $titel);
fillMultipleSelectList("Ms", $titel);
fillMultipleSelectList("Bac", $titel);
print(" </SELECT>\n");
// FUNCTION fillMultipleSelectList
function fillMultipleSelectList($itemWaarde, $itemArray) {
$i= 0;
WHILE ($i < count($itemArray)) {
IF ($itemArray[$i] == $itemWaarde) {
// IT NEVER ENTERS THIS IF!
print("<OPTION VALUE="$itemWaarde" SELECTED>$itemWaarde</OPTION>\n");
$itemIsGeselecteerd = "Ja";
break;
}
$i++;
}
IF ($itemIsGeselecteerd != "Ja") {
print("<OPTION VALUE="$itemWaarde">$itemWaarde</OPTION>\n");
}
} Close fillMultipleSelectList-function
?>- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
Are you sure....
suppose 'gebruikerID' = 1
'gebruikerID' is Dutch for userID.
suppose 'gebruikerID' = 1
'gebruikerID' is Dutch for userID.
Code: Select all
<?php
$behandelaar = new Behandelaar();
$behandelaar->loadBehandelaarMetGebruikerID($_SESSION['gebruikerID']);
$titel = $behandelaar->getTitel();
// FUNCTION loadBehandelaarMetGebruikerID
function loadBehandelaarMetGebruikerID($uID) {
$behandelaar = voerQueryUit("SELECT * FROM Behandelaar WHERE userID=".$uID.";", "Database kan behandelaar niet laden.");
$behandelaarData = vraagAssociatieveRijOp($behandelaar);
IF ($behandelaarData != null) {
$this->ID = $behandelaarData['behandelaarID'];
$this->titel = $behandelaarData['titel'];
}
}
// FUNCTION voerQueryUIT - perform Query
function voerQueryUit($queryTekst,$queryFoutmelding) {
$mysqlConnectie = maakDatabaseConnectie();
$resultaat = mysql_query($queryTekst, $mysqlConnectie);
if (!$resultaat) {
die ("<B>".$queryFoutmelding."</B>");
}
$GLOBALS["LAATSTE_AUTO_INCREMENT_WAARDE"] = mysql_insert_id($mysqlConnectie);
sluitDatabaseConnectie($mysqlConnectie);
return $resultaat;
}
// FUNCTION vraagAssociatieveRijOp
function vraagAssociatieveRijOp($resultaatData) {
$mysqlConnectie = maakDatabaseConnectie();
$assocRij = mysql_fetch_assoc($resultaatData);
sluitDatabaseConnectie($mysqlConnectie);
return $assocRij;
}
?>- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
Mmm, true. Must have forgotten one line. Otherwise it couldn't print Array ( [0] => Prof [1] => Mr [2] => Bac)
Let's have a look....ah yes, there it is
Sorry, but it isn't that simple.
Let's have a look....ah yes, there it is
Code: Select all
<?php
// ....
$behandelaar = new Behandelaar();
$behandelaar->loadBehandelaarMetGebruikerID($_SESSION['gebruikerID']);
$titel = $behandelaar->getTitel();
$titel = explode(";", $titel);
// .... etc
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
okay.. that makes more sense.. hmmmoutputs
maybe you have some spaces in your array? try var_dump($titel) to see...
Code: Select all
<?php
$titel = array('Prof','Mr','Ir','Bac');
function fillMultipleSelectList($itemWaarde, $itemArray) {
$i= 0;
WHILE ($i < count($itemArray)) {
IF ($itemArray[$i] == $itemWaarde) {
// IT NEVER ENTERS THIS IF!
print("<OPTION VALUE="$itemWaarde" SELECTED>$itemWaarde</OPTION>\n");
$itemIsGeselecteerd = "Ja";
break;
}
$i++;
}
IF ($itemIsGeselecteerd != "Ja") {
print("<OPTION VALUE="$itemWaarde">$itemWaarde</OPTION>\n");
}
}
fillMultipleSelectList("Prof", $titel);
fillMultipleSelectList("Mr", $titel);
fillMultipleSelectList("Dr", $titel);
fillMultipleSelectList("Drs", $titel);
fillMultipleSelectList("Ir", $titel);
fillMultipleSelectList("Ing", $titel);
fillMultipleSelectList("Ms", $titel);
fillMultipleSelectList("Bac", $titel);
?>Code: Select all
<OPTION VALUE="Prof" SELECTED>Prof</OPTION>
<OPTION VALUE="Mr" SELECTED>Mr</OPTION>
<OPTION VALUE="Dr">Dr</OPTION>
<OPTION VALUE="Drs">Drs</OPTION>
<OPTION VALUE="Ir" SELECTED>Ir</OPTION>
<OPTION VALUE="Ing">Ing</OPTION>
<OPTION VALUE="Ms">Ms</OPTION>
<OPTION VALUE="Bac" SELECTED>Bac</OPTION>- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL
Do you understand what I am trying to do with this code (off course it is part of a much larger code)?
I'm having many multiple select boxes, like this select box for the title. The problem is the same for all select boxes, because I am using the fillMultipleSelect-function. Selecting several items from a list is not a problem and recording these items (as a string) in the database neither. Retrieving the string-value from the database is no problem either, nor is converting this string back to an array. The problem is, that I want to be able to change my selection. So, if I am accessing this form again, the values in the array should all be shown as selected in the select box.
But it only selects the first value of the array. "Prof"
The second time I'm calling the fillMultipleSelect-function, the IF-comparison simple refuses to work. I don't understand why. If I'm echoing the values of my array, it all seems okay.
Antonie
I'm having many multiple select boxes, like this select box for the title. The problem is the same for all select boxes, because I am using the fillMultipleSelect-function. Selecting several items from a list is not a problem and recording these items (as a string) in the database neither. Retrieving the string-value from the database is no problem either, nor is converting this string back to an array. The problem is, that I want to be able to change my selection. So, if I am accessing this form again, the values in the array should all be shown as selected in the select box.
But it only selects the first value of the array. "Prof"
The second time I'm calling the fillMultipleSelect-function, the IF-comparison simple refuses to work. I don't understand why. If I'm echoing the values of my array, it all seems okay.
Antonie
- Lord Sauron
- Forum Commoner
- Posts: 85
- Joined: Tue Apr 20, 2004 5:53 am
- Location: Tilburg, NL