php hoe doe ik dit.

Gestart doorFreestyle6 reacties15 weergaven

7 berichten · pagina 1 van 1

Freestyle

Lid · Topicstarter

Berichten
7.681
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik heb in mijn tabel producten.
X aantal producten staan.
En daar staat ook in hoeveel keer het verkocht is. Als ik dan per product wil berekenen hoeveel ik heb verdient. Zet ik het in een while. En doe ik: prijs * verkocht.
Maar hoe tel ik dan die prijs van alle producten bij elkaar op??

Moet ik het in een array zetten. En hoe werkt dat dan??
Ik heb dit:

[COLOR= #0000BB]<?php $inkomst[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$iquery[/COLOR][COLOR= #007700])) {[/COLOR]
    [COLOR= #0000BB]$inkomst[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verkocht[/COLOR][COLOR= #007700]]*[/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]prijs[/COLOR][COLOR= #007700]]; 
}[/COLOR] ?>


alvast bedankt
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$inkomst[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$iquery[/COLOR][COLOR= #007700])) {[/COLOR]
    [COLOR= #0000BB]$inkomst[/COLOR] [COLOR= #007700]+=[/COLOR] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verkocht[/COLOR][COLOR= #007700]]*[/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]prijs[/COLOR][COLOR= #007700]]; 
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$inkomst[/COLOR][COLOR= #007700];[/COLOR]
?>


Zo?
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
[COLOR= #0000BB]<?php
$inkomst[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$iquery[/COLOR][COLOR= #007700])) {[/COLOR]
    [COLOR= #0000BB]$inkomst[/COLOR] [COLOR= #007700]+=[/COLOR] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]verkocht[/COLOR][COLOR= #007700]]*[/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]prijs[/COLOR][COLOR= #007700]]; 
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$uitkomst[/COLOR][COLOR= #007700];[/COLOR]
?>
Zo?

en hoe kom jij dan aan $uitkomst als je alleen $inkomst gebruikt sadley
Verander in het scriptje even $uitkomst door $inkomst biggrin
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Waar zie jij dat dan? Mijn script klopt gewoon santabaard
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
Waar zie jij dat dan? Mijn script klopt gewoon santabaard
Als ik naar de oude versie van je bericht kijk, zie ik toch echt $uitkomst staan sadley
0
Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
Waar zie jij dat dan? Mijn script klopt gewoon santabaard
Quote:
Laatst bewerkt door Luukvdo op 30 juli 2011, 161205.

We geloven je hoor hypocrite
0
Freestyle

Lid · Topicstarter

Berichten
7.681
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt!
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren