Etalage
De file on_display.txt ziet er zo uit:
Bloemen,zonnebloemen.jpg,11.95
After shave,aftershave.jpg,34.99
Gezellige huisgenoot,huisgenoot.jpg,75.00
Herrie maken,djembe.jpg,195.00
Hieronder zie je het PHP programma voor de etalage
<?php
$infile = fopen("on_display.txt","r");
if($infile == FALSE){
printf("Error opening file");
exit();
}
printf("<form method='post' action='bestelling.php'>");
printf("<table border='2'>");
printf("<tr>");
printf("<th>Bestelnummer</th><th>Dinges</th>
<th>Alvast kijke</th><th>Prijs</th>
<th>Bestellen</th>");
printf("</tr>");
$artikel=1;
while(!feof($infile)){
$instring = fgets($infile,256);
if($instring=="")break;
$instring=trim($instring);
$woord = explode(",",$instring);
$aantal_woorden = count($woord);
printf("<tr>");
printf("<th>%2s</th>",$artikel);
printf("<td align='center'>%s</td>\n",$woord[0]);
printf("<td align='center'><img src='%s' width='75'></td>\n",$woord[1]);
printf("<td align='center'>€ %s</td>\n",$woord[2]);
printf("<td align='center'>
<input type='checkbox' name='bestel[]' value='%s'>
</td>",$artikel);
printf("</tr>");
$artikel++;
} // while
printf("<tr><td colspan='5' align='center'>
<input type='submit' value='Wat gaat dat kosten'>
</td></tr>");
printf("</table>");
printf("</form>");
fclose($infile);
?>