Jump to content

MaranV

Members
  • Posts

    25
  • Joined

  • Last visited

Everything posted by MaranV

  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.""; } } } } }?>
  16. ah yes excellent, also something I was curious about a follow up question then: if ((is_numeric ( $a & $b )) && ( $a == $b )) why are there 2 ( characters at the start and 2 ) at the end ? because its 2 conditions being set? and then another unrelated one what are the { and } doing? I understand that if not properly placed your code will fail, but i dont see their function or a logic on where to place them
  17. thanks don E, this was not the problem, but thanks for the effort roy, I copied your code, as expected, works like a charm thanks however I have a question, in css (html & css being my meager former experience with Webdesign) I seem to always have to place opposite accalades ( { vs } } vs { ) or the code will not work, but in the php you wrote im seeing (or maybe it really is THIS late lol) you using equal accalades following eachother could you explain what this is exactly? infact, im pretty clueless what accalades do besides that they make or break code
  18. Hi, I`m having a problem with seperating the output of 2 functions, I have specified a unique button to each function (I think) but when I click either one of the buttons the output of the 2 functions is displayed so my question is: how can i get the first button to only display the first output ( the for function without table) and the second button to display the 2nd output (the for function with tables) <?phpif (isset ($_POST["awwyeaa"])) ;for ( $i = 1 ; $i <= 10 ; $i++ ) { print $i." ";}print "<BR /><BR /><BR />";for ( $i ; $i <= 20 ; $i++ ) { print $i." ";}print "<BR /><BR /><BR />";for ( $i ; $i <= 30 ; $i++ ) { print $i." ";}print "<BR /><BR /><BR />";for ( $i ; $i <= 40 ; $i++ ) { print $i." ";}print "<BR /><BR /><BR />";if (isset ($_POST["juppp"])) ;echo "<table border=\"10\" align=\"left\">"; print "<tr>"; for ($i = 1 ; $i <= 10 ; $i++) { print "<td>$i</td>"; } print "</tr>";print "<tr>"; for ($i ; $i <= 20 ; $i++) { print "<td>$i</td>"; } print "</tr>";print "<tr>"; for ($i ; $i <= 30 ; $i++) { print "<td>$i</td>"; } print "</tr>";print "<tr>"; for ($i ; $i <= 40 ; $i++) { print "<td>$i</td>"; } print "</tr>"; ?> _____________________________________________________________________________________and on a sidenote, in a php i wrote earlier i could define the following like this : if (isset ($_POST["testplus"])) { $testplus = $a + $b;echo " Als " . $a . " bij " . $b . " opgeteld wordt is de totale hoeveelheid " . $testplus ;exit; so NO ; after the isset but with a { below it while in the top page code this returns an error and I had to place a ; while removing { an answer to this would be appreciated as to me it seems that php just randomly decided it to require different characters in the same situation :S
  19. he shoots, he scores thanks
  20. thanks for the answer birbal and another question about global scopes this time I used the global code only once in the first if function, yet my functions even work without having the global code in there and on a subsequent note, all the functions function with out how is this possible? w3schools said I need to enter the global code per function <?php $a = $_POST["Invoerlinks"]; $b = $_POST["Invoerrechts"]; if (isset ($_POST["testplus"])) global $a, $b; //(is_numeric ( $a & $b )) && ( $a == $b ))if ((is_numeric ( $a & $b )) && ( $a == $b )) {print "De waarden van $a en $b en zijn gelijk";}elseif ((is_numeric ( $a) && is_numeric($b )) && ( $a !== $b )) {print "De waarden van $a en $b en zijn niet gelijk"; }elseif ((! is_numeric ( $a) && ! is_numeric($b )) && ( $a == $b )) {print "$a is gelijk aan $b";}elseif ((! is_numeric ( $a) && ! is_numeric($b )) && ( $a !== $b )) {print "$a is NIET gelijk aan $b"; } else { print "$a met $b vergelijken is gelijk aan appels met peren vergelijken, het is niet gelijk";}?>
  21. just noticed something ((is_numeric ( $a & $b )) && ( $a == $b )) this works aswell (ironicly i was 1 ( away from a working code myself ....) how is this different from ((is_numeric ( $a) && is_numeric($b )) && ( $a == $b )) is the upper code just shorter or are there any advantages/disadvantages between the 2 ?
  22. ok I got the numeric checking down, thanks again but now I`m trying to do the same text (letters only) based EDIT: forgot to place ! at both numeric checkers here is the working code elseif ((! is_numeric ( $a) && ! is_numeric($b )) && ( $a == $b )) SOLVED - thanks
  23. yes thanks Ingolme, it looks a bit odd but this is the only way the function works for me roy, I exchanged the || for && and removed the spaces you left after the $ in the b variables and now it seems to be working like a charm if ((is_numeric ( $a) && is_numeric($b )) && ( $a == $b )) gonna mess around with multiple ifs to get echos for different entries, thanks for the help
  24. Hi, new guy to php here. I`m trying to put 2 if conditions (true) together as you can see below.I checked on various sites and from what I understand /$/b/) - remove the / characters to get the actual code I typed instead of this smirking smiley if (is_numeric ($a & $ ) || ($a == $ should be working but it gives me: Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in E:\xamp\xampp\htdocs\PHP\week1opdr4\phpweek1opdr4.php on line 14 I have also tried replacing || by &&,syntax error, unexpected '&&' (T_BOOLEAN_AND) <?php $a = $_POST["Invoerlinks"]; $b = $_POST["Invoerrechts"]; if (isset ($_POST["testplus"])) global $a, $b; if (is_numeric ($a & $ ) || ($a == $ { print "$a is wel gelijk aan $b en zijn beide nummers"; } else { print "$a is NIET gelijk aan $b"; } ?> any help on getting these 2 conditions working to produce an echo/print would be appreciated, ALOT (somehow spending 10 hours on your first home work assignment isn`t that motivating ^^)
×
×
  • Create New...