emailconfirmed, nsInternRO, nsInternRW, Administrators
3,356
edits
mNo edit summary |
m (→Das Backend) |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 77: | Line 77: | ||
// ********** default values ********** | // ********** default values ********** | ||
// fill products with some default values (products) | // fill products with some default values (products) | ||
// note that this is a very simplified example, | |||
// therefore we're using a hard-coded products array here to easily update the form-values | |||
// in a "real life" example, we'd catch the products from the database | |||
$products = array('Shampoo', 'Soap'); | $products = array('Shampoo', 'Soap'); | ||
$sql = "INSERT INTO products | $sql = "INSERT INTO products | ||
| Line 94: | Line 97: | ||
foreach($products as $prodName) { | foreach($products as $prodName) { | ||
// replace float "," with "." $_POST['prodPrice'] is from the posted form | // replace float "," with "." $_POST['prodPrice'] is from the posted form | ||
// to prevent wrong values due to german floating point separator "," (comma) instead of the english "." (dot) | |||
$prodPrice = str_replace(",",".",$_POST['prodPrice_'.$i]); | $prodPrice = str_replace(",",".",$_POST['prodPrice_'.$i]); | ||
// update db | // update db | ||
| Line 118: | Line 122: | ||
while($entry = mysql_fetch_array($result, MYSQL_BOTH)) { | while($entry = mysql_fetch_array($result, MYSQL_BOTH)) { | ||
printf("<tr> | printf("<tr> | ||
<td>%s</td> | |||
<td><input type='text' name='prodPrice_$i' value='%01.2f' size='8'></input></td> | |||
</tr>", | |||
$entry[prodName], | |||
$entry[prodPrice] ); | |||
$i++; | $i++; | ||
} | } | ||
| Line 135: | Line 139: | ||
</source> | </source> | ||
== | == Das Frontend == | ||
...ist im Prinzip das Gleiche wie das Backend, nur sehr viel einfacher, da wir uns nicht darum kümmern müssen, die Werte zu aktualisieren. Außerdem kann man davon ausgehen, dass alle Tabellen und die Datenbank bereits exisitieren. | ...ist im Prinzip das Gleiche wie das Backend, nur sehr viel einfacher, da wir uns nicht darum kümmern müssen, die Werte zu aktualisieren. Außerdem kann man davon ausgehen, dass alle Tabellen und die Datenbank bereits exisitieren. | ||
| Line 164: | Line 168: | ||
while($entry = mysql_fetch_array($result, MYSQL_BOTH)) { | while($entry = mysql_fetch_array($result, MYSQL_BOTH)) { | ||
printf("<tr> | printf("<tr> | ||
<td>%s</td> | |||
<td>%01.2f €</td> | |||
</tr>", | |||
$entry[prodName], | |||
$entry[prodPrice] ); | |||
$i++; | $i++; | ||
} | } | ||