Created
December 17, 2011 23:22
-
-
Save imme-emosol/1491771 to your computer and use it in GitHub Desktop.
paginadeel voor bestellijst/winkelwagen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
if ( !isset( $_SESSION[ 'bestellingen' ] ) ) | |
$_SESSION[ 'bestellingen' ] = array(); | |
if ( isset( $_POST[ 'leegmaken' ) ) | |
{ | |
$_SESSION[ 'bestellingen' ] = array(); | |
} | |
elseif ( isset( $_POST[ 'product_id' ] ) ) | |
{ | |
$product_id = 1 * $_POST[ 'product_id' ]; | |
if ( !in_array( $product_id , $_SESSION[ 'bestellingen' ] ) ) | |
$_SESSION[ 'bestellingen' ][ $product_id ] = 0; | |
$_SESSION[ 'bestellingen' ][ $product_id ]++; | |
} | |
$bestellijst = array(); | |
if ( !empty( $_SESSION[ 'bestellingen' ] ) ) | |
{ | |
$db = new MySQLi( 'localhost' , 'root' , '' , 'webwinkel' ); | |
$sql = 'SELECT * FROM `producten` WHERE product_id IN(' . implode( ' , ' , array_keys( $_SESSION[ 'bestellingen' ] ) ) . ') '; | |
$r = $db->query( $sql ) | |
OR die( '<h2>Oeps, er ging iets mis.</h2>' . $db->error . '<hr />' . $sql . '<pre>^^</pre>' ); | |
while ( $product = $r->fetch_assoc() ) | |
$bestellijst[] = $product + array( 'aantal' => $_SESSION[ 'bestellingen' ][ $product[ 'product_id' ] ] ); | |
} | |
?> | |
<h2>Bestellingen</h2> | |
<?php if ( empty( $bestellijst ) ) : ?> | |
<p>Nog geen bestellingen</p> | |
<?php else : ?> | |
<table> | |
<thead><tr><td>product</td><td>aantal</td></tr></thead> | |
<tbody> | |
<?php foreach ( $bestellijst as $product ) : ?> | |
<tr><td><?php echo $product[ 'naam' ]; ?></td><td><?php echo $product[ 'aantal' ]; ?></td></tr> | |
<?php endforeach; ?> | |
</tbody> | |
<tfoot> | |
<tr><td colspan="2" | |
><form action="<?php echo $_SERVER[ 'REQUEST_URI' ]; ?>" method="POST"> | |
<input type="hidden" name="leegmaken" value="TRUE :þ " /> | |
<input type="submit" value="leegmaken" /> | |
</form> | |
<form action="<?php echo $_SERVER[ 'REQUEST_URI' ]; ?>" method="GET"> | |
<input type="hidden" name="pagina" value="bestellen " /> | |
<input type="submit" value="afrekenen" /> | |
</form> | |
</td></tr> | |
</tfoot> | |
</table> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment