I am attempting to populate three dropdown menus: Agency, City and Date with test data for a flushot web site. I am confused with the code. The text file, "data.dat", contains the information with the various elements seperated by <|>'s. All together there are the following files: data.dat, test_view.php, index.php(the main webpage which has the dropdowns, and results.php.
Here is the test_view.php:
<FORM action=results.php name=form>
<?
$content_array = file('data.dat');
$Total_records = count($content_array);
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
$dates[$RecCount]=$elements[6];
$cities[$RecCount]=$elements[3];
$agencies[$RecCount]=$elements[5];
}
$Udates=array_values(array_unique ($dates));
$Ucities=array_values(array_unique ($cities));
$Uzips=array_values(array_unique ($agencies));
$Dcount=count($Udates);
$Ccount=count($Ucities);
$Zcount=count($Uagencies);
print '<select name=date onChange="form.submit();">';
print "<option value=null><i>select a date</i></option>";
for ($i=0; $i<$Ccount; $i++)
print "<option value=$Udates[$i]>$Udates[$i]</option>";
print "</select>";
print '<select name=city onChange="form.submit();">';
print "<option value=null><i>select a city</i></option>";
for ($i=0; $i<$Ccount; $i++)
{ print "<option value=";
print '"';
print "$Ucities[$i]";
print '"';
print ">$Ucities[$i]</option>";
}
print "</select>";
print '<select name=agency onChange="form.submit();">';
print "<option value=null selected><i>select a zip</i></option>";
for ($i=0; $i<$Zcount; $i++)
print "<option value=$Uagencies[$i]>$Uagencies[$i]</option>";
print "</select></form>";
print "<BR><BR><BR><table><tr><td colspan=7>There are actually $Total_records Events</td></tr>";
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
print "<tr><td>$elements[0]</td><td>$elements[1]</td><td>$elements[2]</td><td>$elements[3]</td><td>$elements[4]</td>
<td>$elements[5]</td><td>$elements[6]</td><td>$elements[7]</td></tr>";
}
?>
</table>
Here is the part of the index.php in the "head"of the html dealing with the dropdowns:
<script>
function city_fun(){
form1.date.selectedIndex=0;
form1.agency.selectedIndex=0;
window.open('about:blank', 'resultWin', 'width=555,height=300,resizable=yes,scrollbars=auto,menubar=no,toolbar=no,directories=no,location=no,status=no');
document.form1.target = "resultWin";
document.form1.submit();
}
function date_fun(){
form1.city.selectedIndex=0;
form1.agency.selectedIndex=0;
window.open('about:blank', 'resultWin', 'width=555,height=300,resizable=yes,scrollbars=auto,menubar=no,toolbar=no,directories=no,location=no,status=no');
document.form1.target = "resultWin";
document.form1.submit();
}
function agency_fun(){
form1.date.selectedIndex=0;
form1.city.selectedIndex=0;
window.open('about:blank', 'resultWin', 'width=555,height=300,resizable=yes,scrollbars=auto,menubar=no,toolbar=no,directories=no,location=no,status=no');
document.form1.target = "resultWin";
document.form1.submit();
}
function showAll(){
form1.date.selectedIndex=0;
form1.city.selectedIndex=0;
form1.agency.selectedIndex=0;
form1.viewAll.value=1;
window.open('about:blank', 'resultWin', 'width=555,height=300,resizable=yes,scrollbars=auto,menubar=no,toolbar=no,directories=no,location=no,status=no');
document.form1.target = "resultWin";
document.form1.submit();
}
</script>
And finally, here is the "Body" part of the index.php:
<font face= "century schoolbook" size="4" color="#800000"><strong>To Find a Flu Vaccine Clinic by <br>CITY, AGENCY or DATE<br>click a Button Below</strong></font>
<br><br>
<br>
<FORM ACTION="results.php" name=form1>
<table width=300>
<tr>
<td>
Select City
<select name=city onChange="city_fun();">
<option value=null></option>
<?PHP
$content_array = file('data.dat');
$Total_records = count($content_array);
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++){
$elements = explode("<|>", $content_array[$RecCount]);
$tcities[$RecCount] = $elements[3];
$tdates[$RecCount] = $elements[6];
$tagencies[$RecCount] = $elements[5];
}
$cities=array_values(array_unique ($tcities));
$dates=array_values(array_unique ($tdates));
$agencies=array_values(array_unique ($tagencies));
$num_cities =count($cities);
$num_dates =count($dates);
$num_agencies =count($agencies);
For ($i = 0; $i < $num_cities; $i++)
print "<option value='$cities[$i]'>$cities[$i]</option>";
print'
</select>
</td>
<td>
Select Date
<select name=date onChange="date_fun();">
<option value=null></option>
';
For ($i = 0; $i < $num_dates; $i++)
print "<option value=$dates[$i]>$dates[$i]</option>";
print'
</select>
</td>
<td>
Select Agency <select name=agency onChange="agency_fun();">
<option value=null></option>
';
For ($i = 0; $i < $num_agencies; $i++)
print "<option value=$agencies[$i]>$agencies[$i]</option>";
?>
</select>
</td>
</tr>
</table>
<input type="button" style="background-color: #FFFFFF; " value="To View Entire Clinic Schedule" onclick="showAll();">
<input type=hidden name=viewAll value=0>
</form>
The problem is, when I first put this together, the data.dat file had 7 different entities (City, Adress, Phone, contact person, etc). Now there are 11.
Here are the 11 in the data.dat:
City Date Day Time Agencyname Location Building/room Street Zip Phone# contact person
And an example:
1<|>Catholic Health System<|>St. Theresa Avila<|>Parish Hall <|>Akron <|>14001<|>08/15/2003<|>8:00AM - 5:00PM<|>542-9109
2<|>Univera<|>Rite Aid<|> #14 <|> North Tonawanda<|>14001<|>08/15/2003<|>7:00AM - 4:00PM<|>544-9103
I know this is very long winded, but the only way to explain this was to post all the code.
If anyone has any idea how I can get the three dropdowns to pull ALL the data for each queried record to the pop up form, I would appreciate any feedback.
Thank you for your time.
Bufhal