truncate(); $table = new Product(); $table->truncate(); header("Location: example.php?message=".urlencode("Tables truncated")); exit; } if ( $_POST['newshopper'] ) { $aShopper = new Shopper(); $aShopper->setField('name', $_POST['newshopper'] ); $aShopper->save(); header("Location: example.php?message=".urlencode("New shopper added")); exit; } if ( $_POST['newproduct'] ) { $aProduct = new Product(); $aProduct->setField('name', $_POST['newproduct'] ); $aProduct->save(); header("Location: example.php?message=".urlencode("New product added")); exit; } if ( $_POST['shopper'] && $_POST['product'] ) { $aShopper_Product = new Shopper_Product(); $aShopper_Product->setField('sid', $_POST['shopper']); $aShopper_Product->setField('pid', $_POST['product']); $aShopper_Product->setField('date_added', date("Y-m-d H:i:s")); $aShopper_Product->save(); header("Location: example.php?message=".urlencode("New association added")); exit; } $aShoppers = Shopper::getAll(); $aProducts = Product::getAll(); ?>
The write up on this lives here: http://www.koopman.me/2008/11/dbtable-and-all-its-glory/
=htmlspecialchars($_GET['message'])?>
Truncate all data:| Add shopper: | Add Product: | Add Association |
| Name | Products | ".htmlspecialchars($aShopper->getField('name'))." | \n"; print ""; $products = $aShopper->getProducts(); foreach($products as $aProduct) print htmlspecialchars($aProduct->getField('name')).", "; print " | \n"; print "\n"; } ?>
| Name | Shoppers | ".htmlspecialchars($aProduct->getField('name'))." | \n"; print ""; $shoppers = $aProduct->getShoppers(); foreach($shoppers as $aShopper) print htmlspecialchars($aShopper->getField('name')).", "; print " | \n"; print "\n"; } ?>