Vraag & Antwoord

Webprogrammeren & scripting

Nummers optellen en verschil uitrekenen

7 antwoorden
  • Ik ben bezig met een php pagina waarmee je dus een aantal input boxes hebt waar je een nummer in kan voeren en onderaan is dan een input box waar het totaal van alle nummers uit moet komen. Het is bedoeld voor een soort van shopping cart systeem, en dus is het idee dat je de prijzen van verschillende items kan invoeren en de totaalprijs automatisch wordt uitgerekend. Ik heb al wat gegoogled maar ik kan er maar niet uitkomen... Wie kan me helpen? Dank. Let op: ik ben een php-noob
  • [quote:4ade618b84="carlobernardini"]Let op: ik ben een php-noob[/quote:4ade618b84]Let op: we doen hier niet aan scriptrequests, laat dus eerst maar eens zien wat je nu al hebt en wat je dan niet snapt...
  • Ik weet niet echt of je wilt weten wat ik nu heb, het is nogal veel :D Hier is het: [code:1:39c125659a] <?PHP if(!$_POST['act']) { echo ' <form method="post" action="'.$_SERVER['PHP_SELF'].'"> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500" height="20"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z1" type="text" class="searchform2" id="z1" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500" height="20"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z2" type="text" class="searchform2" id="z2" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500" height="20"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z3" type="text" class="searchform2" id="z3" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500" height="20"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z4" type="text" class="searchform2" id="z4" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500" height="20"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z5" type="text" class="searchform2" id="z5" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z6" type="text" class="searchform2" id="z6" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z7" type="text" class="searchform2" id="z7" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z8" type="text" class="searchform2" id="z8" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z9" type="text" class="searchform2" id="z9" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z10" type="text" class="searchform2" id="z10" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z11" type="text" class="searchform2" id="z11" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z12" type="text" class="searchform2" id="z12" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z13" type="text" class="searchform2" id="z13" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z14" type="text" class="searchform2" id="z14" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z15" type="text" class="searchform2" id="z15" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z16" type="text" class="searchform2" id="z16" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z17" type="text" class="searchform2" id="z17" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z18" type="text" class="searchform2" id="z18" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z19" type="text" class="searchform2" id="z19" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z20" type="text" class="searchform2" id="z20" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z21" type="text" class="searchform2" id="z21" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z22" type="text" class="searchform2" id="z22" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z23" type="text" class="searchform2" id="z23" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z24" type="text" class="searchform2" id="z24" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z25" type="text" class="searchform2" id="z25" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z26" type="text" class="searchform2" id="z26" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z27" type="text" class="searchform2" id="z27" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"> </td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z28" type="text" class="searchform2" id="z28" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z29" type="text" class="searchform2" id="z29" size="5"></td> </tr> <tr bgcolor="#F0F0F0" class="facSec1"> <td width="100" height="20" class="facSec1"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="100" height="20"><input name="textfield" type="text" class="searchform2" size="5"></td> <td width="500"><input name="textfield" type="text" class="searchform2" size="50"></td> <td width="100"><input name="z30" type="text" class="searchform2" id="z30" size="5"></td> </tr> <tr> <td height="20" class="bodyPadding"> </td> <td height="20"> </td> <td height="20"> </td> <td height="20"><select name="act" class="searchform"> <option selected value="add">[ + ]</option> <option value="sub">[ - ]</option> </select></td> </tr></form> <tr bgcolor="#CCCCCC"> <td height="20" class="facSec1"> </td> <td height="20"> </td> <td height="20"><div align="right"> <input name="Submit" type="submit" class="searchform" value="TOTAAL"> </div></td> <td height="20"><span class="facSec1"> '; }else{ if($_POST['act'] == 'add') { $calc = ($_POST['z1']+$_POST['z2']+$_POST['z3']+$_POST['z4']+$_POST['z5']); $op = '+'; } if($_POST['act'] == 'sub') { $calc = ($_POST['z1']-$_POST['z2']-$_POST['z3']-$_POST['z4']-$_POST['z5']); $op = '-'; } echo $_POST['z1'].' '.$op.' '.$_POST['z2'].' '.$op.' '.$_POST['z3'].' '.$op.' '.$_POST['z4'].' '.$op.' '.$_POST['z5'].' = '.$calc; } ?> [/code:1:39c125659a] ...Maar het werkt dus nog niet.... :( Wat doe ik verkeerd? Alvast bedankt weer[/code]
  • aan t eind van de echo() staat ergens </form>. Haal deze weg en voeg aan t eind van die echo() toe </span></td></tr></form>. (voor! de qoute ['] ) Nu doet ie tenmisnte iets...
  • Jippie! nu telt ie het inderdaad bijelkaar op, maar het idee is eigelijk, dat het totaal bedrag dan onder de rij met andere bedragen komt te staan, en niet dat de tabel verdwijnt en hij het alleen weergeeft als: 3 + 3 + 3 = 9 (om een voorbeeld te noemen) Hoe moet dat dan? Alvast bedankt
  • dan moet je de else weghalen (en natuurlijk de bijbehorende accolades), dan wordt altijd die som getoond. Maar er zitten nog wel wat fouten in: je moet if(empty($_POST['act'])) gebruiken of isset() Alle HTML die je echoot kan je beter gewoon HTML laten: [code:1:186d9af9d3] <? if() { ?> <!-- je html //--> <? } //end-if //en nu de rest van je php-code ?> [/code:1:186d9af9d3] Daarnaast lijkt heel veel wel erg op elkaar (al die <tr><td> wat er ook staat...) Dat kan vast en zeker met een loopje. Er zijn velden met dezelfde naam: als bij beiden wat wordt ingevuld blijft maar een van de wwarden bewaard
  • hoe moet ik dat dan doen, die else weghalen, zonder dat ik het script overhoop haal? (kan je ajb even de bovenstaande code bewerken tot wat jij bedoeld)? Alvast bedankt weer :wink:

Beantwoord deze vraag

Weet jij het antwoord op deze vraag? Registreer of meld je aan met je account

Dit is een gearchiveerde pagina. Antwoorden is niet meer mogelijk.