Jump to content

MaranV

Members
  • Posts

    25
  • Joined

  • Last visited

MaranV's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I wrote this code as an assignment for php class, only after I was done and concluded it worked, I saw a comment on the assignment "returns true or false" so I added a true & a false to test, remaining clueless why this is necessary. I would appreciate it if someone could answer the questions i put in the comments $hypo = $_POST["hypo"]; $mndsalaris = $_POST["mndsalaris"]; $mijnsom = hypotheekchecker( $hypo, $mndsalaris ); print "$mijnsom <br>"; $hypomax = maxhypo( $hypo, $mndsalaris ); print "$hypomax";function hypotheekchecker( $lening, $maandsalaris ) {$BenodigdeRente = $lening * 0.057;$BenodigdMsal = $maandsalaris * 3; if ($BenodigdeRente <= $BenodigdMsal) {echo " Gefelicflapstaart, u krijgt de hypotheek van ". bedrag_met_opmaak($lening);return true; //1. what exactly does this do besides add a 1 after the above echo is displayed ? my function works the same without this line, excluding the 1 (probaly a boolean for true or something??)} else { echo "Helaas u verdient te weinig en u krijgt de hypotheek van ". bedrag_met_opmaak($lening) ." niet"; return false; // same thing, except this doesn`t add anything after the above echo } }function maxhypo ($lening, $maandsalaris) {$BenodigdMsal = $maandsalaris * 3; $maxbedrag = $maandsalaris * 3 * 17.54385965;echo "De maximale hypotheek die u mag afsluiten bedraagt " . bedrag_met_opmaak($maxbedrag);} function bedrag_met_opmaak( $invoer_bedrag ) { $antwoord = "€ " . number_format($invoer_bedrag, 2); return $antwoord;}
  2. yes thanks, I had that figured out by now ^^ eventually o and for the ones interested, here is the fully functional code $B = $_POST["InvoerBoven"]; $O = $_POST["InvoerOnder"]; $cijfers = array( "v1cp11" => 6.9, "v1cp1a" => 7.8, "v1ok11" => 4.8, "v1ok12" => 5.1, "vlok" => 9.1); if (isset($_POST["goknop"])) {echo "<table border=\"10\" align=\"left\">"; if(isset($cijfers[$B])){ //*1 if (!empty($O)) $cijfers[$B] = $O; // *2 foreach ($cijfers as $key => $value) { if ($key == $ { if (empty($O)){ print "Voor dit al eerder toegevoegde Vak $key is het cijfer $value behaald. <br/><br/>"; } if (!empty($O)){ print "Voor dit al eerder toegevoegde Vak $key is een cijferwijziging doorgegeven: $value. <br/><br/>"; } } print "<td>$key</td> <td>$value</td><tr> "; } } elseif (!isset($cijfers[$B])){ print "Nieuw vak $B toegevoegd met het behaalde cijfer: $O. <br/><br/>"; print "<td>$B</td> <td>$O</td><tr> "; foreach ($cijfers as $key => $value) { print "<td>$key</td> <td>$value</td><tr> "; } } }
  3. Ok, back, had a chat with a teacher, cleared up (well I hope I did) issues with including statements in the right ifs (and about indenting ^^) thanks for the help guys
  4. I thought I did have that clear: if the condition to the if statement is NOT met it checks if this one (elseif) is true, and then proceeds to execute the code below it (in this case the echo) I`m afraid i dont understand the question Which if statement is that else part of? - I thought the elseif was entirely seperate from the above if Is it part of the one in the foreach loop? - could you explain how it is relevant for the first if to be "in" the loop ? ( I thought the loop just generated info and then made those variables approachable)
  5. Changed the code, stil having the same issue though =/ $R = $_POST["Invoerrechts"]; $L = $_POST["Invoerlinks"]; $cijfers = array( "v1cp11" => 6.9, "v1cp1a" => 7.8, "v1ok11" => 4.8, "v1ok12" => 5.1, "vlok" => 9.1); if (isset($_POST["goknop"])) { if (!empty($R)) $cijfers[$L] = $R; foreach ($cijfers as $key => $value){if ($key == $L){print "Al eerder toegevoegd Vak $key heeft een cijferwijziging doorgekregen: $value . <br/>"; } } } elseif($key !== $L){echo "key u no exist";}
  6. ah ok thanks, could someone read through my code and check whats going wrong ? $R = $_POST["Invoerrechts"]; $L = $_POST["Invoerlinks"]; $cijfers = array( "v1cp11" => 6.9, "v1cp1a" => 7.8, "v1ok11" => 4.8, "v1ok12" => 5.1, "vlok" => 9.1); if (isset($_POST["goknop"])) { if (!empty($R)) $cijfers[$L] = $R;{ foreach ($cijfers as $key => $value) {{if ($key == $L) {print "Al eerder toegevoegd Vak $key heeft een cijferwijziging doorgekregen: $value . <br/>";}}}}}elseif($key !== $L) {echo "key u no exist";}
  7. if ($key == $L) {echo "key known"; If I understand this if statements checks if the value entered in the $L variable is equal to a key, what would the opposite of this be? (so an if statement for the $L variable NOT being a key) ifelse ($key !== $L) {echo "key unknown"; I have tried this, but it seems to blatantly ignore me and just keeps displaying the above text echo any ideas?
  8. brilliant its working, thanks a bunch, I`ll get some rest now, work out the details tomorrow
  9. ok check the only variable I would have to set is the $R (which is the entry field) since I only want the entries made in the $R to be able to change the values (we can call those elements too?) assigned to the keys. Am I right there? thats where the real issue is, I don`t know how to tell php let the entry made in $R overwrite my defaults
  10. yea that is what im trying, to overwrite the 6.9 (as in the example in my post above) by the text entered in $R, but I`m not sure how to write this in php when you say "or else use the default." do you mean that if $R is empty it will use the 6.9? if so, yes that is exactly what I want
  11. ah cool thanks, I think I`ll just ask my teacher though because most of my examples comtained a loop (so he probaly expects us to use loops in the assigments) another question though, "v1cp11" => 6.9 OR $R I`d like the value to be 6.9 unless text is entered in $R (then I`d like the text entered in $R to be the value), is something like this possible? the idea is that a grade is displayed as noted in array, unless we enter a grade to replace it
  12. so when someone enters a key they get the matching value
  13. yep thanks I`ve changed my code to only hold 1 foreach, however I have the problem the last echo only returns the first key => value in my $cijfers array foreach ($cijfers as $key => $value) { if ($key == $L) { print "Vak met code $key en cijfer $value is toegevoegd. <br/>";{ echo "<br/>Dit zijn de cijfers van alle vakken: <br/>"; echo "$key - $value <br/>"; ____________________________________________________________________________only first key => value displayed________________________________________________________________________________ but when I use 2 x foreach, it shows the results as i want (all keys and the matching values foreach ($cijfers as $key => $value) { if ($key == $L) { print "Vak met code $key en cijfer $value is toegevoegd. <br/>";{ echo "<br/>Dit zijn de cijfers van alle vakken: <br/>"; foreach ($cijfers as $key => $value) { echo "$key - $value <br/>"; I`m trying to understand why this is happening, but I can`t really come up with a reason why I would need the duplicated foreach
  14. to be honest I just copied the example from my book and have been (attempt at) logicly changing/adding stuff to match my assignment
  15. I`m trying to echo my array in the following manner: key => value - so the output for example would(should) be: v1cp11 9.4v1cp1a 7.8 going on like this until the array $cijfers is displayed this seems to work fine, except for the fact it duplicates the output for every key => value I have in my array, what am I doing wrong, and how can I match the display I would like (as mentioned above)? <?php $R = $_POST["Invoerrechts"]; $L = $_POST["Invoerlinks"]; $cijfers = array( "$L" => $R, "v1cp11" => 9.4, "v1cp1a" => 7.8, "v1ok11" => 4.8, "v1ok12" => 5.1, "vlok99" => 9.1); if (isset($_POST["goknop"])) { foreach ($cijfers as $key => $value) { if ($key == $L) { print "Het cijfer voor vak $key is een $value<br/>"; foreach ($cijfers as $value) { foreach ($cijfers as $key => $value) { echo $key." - ".$value.""; } } } } }?> edit------________________________________________________________________________________________________________________________ I changed code a bit, seems the foreach ($cijfers as $value) was causing the duplicates on another note, is there a way to put the echo $key." - ".$value.""; somewhere near the first foreach ($cijfers as $key => $value) { ? it feels a bit redundant i need to place ($cijfers as $key => $value) { twice <?php // in_array() effe onthouden - ik denk; if in_array (SL == "v1cp11) print "v1cp11 bestaat al, het nieuwe cijfer is $R" // $_session" is nodig als je het wil onthouden (niet nodig in de opdracht) $R = $_POST["Invoerrechts"]; $L = $_POST["Invoerlinks"]; $cijfers = array( "$L" => $R, "v1cp11" => $R, "v1cp1a" => 7.8, "v1ok11" => 4.8, "v1ok12" => 5.1, "vlok" => 9.1); if (isset($_POST["goknop"])) { foreach ($cijfers as $key => $value) { if ($key == $L) { print "Het cijfer voor vak $key is een $value<br/>"; { foreach ($cijfers as $key => $value) { echo $key." - ".$value.""; } } } } }?>
×
×
  • Create New...