Hello, I’m trying to use a file with my php code in order to display the results. An example of what I want my code to produce is this:
Marigold
Records selected: 7
Total sold: 41
Here is my HTML
[php]
<head>
<!-- Insert CSS here. -->
</head>
<body>
<form id = '' name = '' action='php 06.php' method='post' class = ''>
<select id = 'flower' name = 'flower'>
<option value = '1'>marigold</option>
<option value = '2'>rose</option>
<option value = '3'>tulip</option>
<input type = 'submit' value = 'SEARCH' class = '' id = 'search'>
</select>
</form>
<!-- Insert JavaScript here. -->
</body>
[/php]
and my php
[php]<?php
$flower = $_POST[$flower];
$flowerSelectedNames = explode("^","Marigold^Rose^Tulip"); // <= = This creates an array with three values.;
$flowerSelected = $flowerSelectedNames[$flower - 1]; // <= = This gets the array value for the selected flower type.;
$flowerSelected = trim($flowerSelected); // <= = $flowerSelected is what to display in the span.;
$file = fopen("data/flower sales.dat","r");
$records = 0;
$total = 0;
while(!feof($file)) {
$row = fgets($file); // Read one record.;
$row = trim($row); // Remove excess characters.;
if ($flower == substr($row,0,1)) {
$records++;
$quantity = substr($flower,1,3);
$quantity = trim($quantity);
$LLC = substr($row,1,3);
$total = $quantity + $LLC;
};
};
[/php]