Script help ???

hi, all. I have made my own report selector script for the monthly and yearly reports. For the yearly reports script the combo box is automatically displaying the word “Year” in the combo box when it loads, but the month script is not, and i dont have a clue why not. I have even copied the code over to that script and it still not working. I also have another script to select dayvideo files and its doing the same thing.

I need to to say “Year” but instead it loads with 2010 in the combo box. I would be very greatefull if you could have a look at the code for me. Bear in mind i dont know much about forms and php, ive kinda learnt on the go and threw things together.

<!-- Begin Report Selector for Monthly Climate Data & Monthly NOAA -->
if (isset($_POST['submit']))
	$month = $_POST['month'];
	$year = $_POST['year'];
	$type = $_POST['type'];

<form name="prev-monthly-rep" id="prev-monthly-rep" action="<?php $SITE['REQURI'] ?>" method="post">
<select name="month" id="month">
<option id="month" value="month" selected="selected">Month</option>
<option id="01" value="01" <?php if ($month == '01') {echo "selected=\"selected\"";} ?>>01</option>
<option id="02" value="02" <?php if ($month == '02') {echo "selected=\"selected\"";} ?>>02</option>
<option id="03" value="03" <?php if ($month == '03') {echo "selected=\"selected\"";} ?>>03</option>
<option id="04" value="04" <?php if ($month == '04') {echo "selected=\"selected\"";} ?>>04</option>
<option id="05" value="05" <?php if ($month == '05') {echo "selected=\"selected\"";} ?>>05</option>
<option id="06" value="06" <?php if ($month == '06') {echo "selected=\"selected\"";} ?>>06</option>
<option id="07" value="07" <?php if ($month == '07') {echo "selected=\"selected\"";} ?>>07</option>
<option id="08" value="08" <?php if ($month == '08') {echo "selected=\"selected\"";} ?>>08</option>
<option id="09" value="09" <?php if ($month == '09') {echo "selected=\"selected\"";} ?>>09</option>
<option id="10" value="10" <?php if ($month == '10') {echo "selected=\"selected\"";} ?>>10</option>
<option id="11" value="11" <?php if ($month == '11') {echo "selected=\"selected\"";} ?>>11</option>
<option id="12" value="12" <?php if ($month == '12') {echo "selected=\"selected\"";} ?>>12</option>
<select name="year" id="year">
<option value="year" id="year" selected="selected">Year</option>
<option value="2009" id="2009" <?php if ($year == '2009') {echo "selected=\"selected\"";} ?>>2009</option>
<option value="2010" id="2010" <?php if ($year == '2010') {echo "selected=\"selected\"";} ?>>2010</option>
<select name="type" id="type">
<option value="type" id="type" selected="selected">Report Type</option>
<option value="noaa" id="noaa" <?php if ($type == 'noaa') {echo "selected=\"selected\"";} ?>>Monthly NOAA Report</option>
<option value="climate" id="climate" <?php if ($type == 'climate') {echo "selected=\"selected\"";} ?>>Monthly Climate Data Report</option>
<input type="submit" name="submit" id="submit" value="Submit" />

$month = $_POST['month'];
$year = $_POST['year'];
$type = $_POST['type'];
$htm = 'htm';
$html = 'html';
$noaa = 'dailynoaareport';
$climate = 'climatedataout';
$monthlynoaarep = $noaa . $month . $year . $html;
$monthlyclimaterep = $climate . $month . $year . $htm;

if (($month == 'month') ||($year == 'year') || ($type == 'type') || ($month == '') ||($year == '') || ($type ==''))
	echo "Please select a report to view.";

if ((file_exists($monthlynoaarep)) || (file_exists($monthlyclimaterep)))

	if ($type == 'noaa')
		echo "You are viewing the monthly NOAA report for " . $month . " " . $year . ".";

	else if ($type == 'climate')
		echo "You are viewing the monthly climate report for " . $month . " " . $year . ".";
		echo "Sorry but that report for " . $month . " " . $year . " is unavailable.";	

<!-- End Report Selector for Monthly Climate Data & Monthly NOAA -->

Thanks Liam

I just copied your code, I see “Month” in the box, is that what isn’t working for you? What’s the url of your script?

Hi niko, thanks for checking it for me. It was “Year” that wasnt working but appears to be working on the link you provided. hmm, i will upload it to my site later as ive only tested it locally. I will have another look at it in the morning as its 1am here now. How is it possibly working fine for you but showing “2010” for me on 2 scripts. Well i wont figure it out now my head is already asleep. :).


hi, the url is; . But it seems to be working now??, confusing. I cant see why it wont work locally but its displaying the right text now on the site.


Might be a lot easier to just change the selection to a Year-Month combined field. That way your script can check to see what is available and display what it found so that the visitor can’t select something you can’t display.


etc… if you use ISO data format like above they can easily be sorted either most current or oldest first.

Might make the report type a radio button rather than a drop down. One less drop down to select. Many users will select one or the other but forget one which just gives them an error. Make it easier for them.

Hi, thanks for that TNETWeather, i think i might do that i like that idea and seems alot easier. Also as you say change them to radio buttons could be easier too. Ive just found something else to fix as well anyway. Apart from that it seems to be displaying correctly.

Doesnt work at the moment due to that other error, i completely forgot to give the elements different id’s and because both scripts are on 1 page of course you change one and the others change. Durr!. Just got to change those and i will most liekly make the modifications you suggested.

Im not sure how to make it check to see whats there, Does that involve arrays?, because they would have to be sorted aswell. and im not very good with those. Ive opted for the show all dates and if its not there just echo and error saying that report is unavailable.

Maybe i can implement that later on when i learn more.


You just need to know where the files are and what format they are in. You can then use PHP to read the directory and create the list on the fly. Arrays make it easier to collect the info and then be able to sort what it found but don’t have to use them. Arrays are your friend though.

The PHP opendir and readdir functions allow you to look at files on your webserver to do what you want with them. Open the directory that has the files you want to display and store them into an array. You can then output the form option element to then display as options the files that are actually there.

A example is below… something I use for noaareports. Kinda extracted it from my actual scripts…


$DEBUG = 1;

$mnthname = array('January', 'February', 'March', 'April', 'May', 'June', 
    'July', 'August', 'September', 'October', 'November', 'December');

// Location of where the files are located
$noaa_files= "weather/";

// What filename are we looking for
$noaa_name= "dailynoaareport-";

dbmsg("Dir = [" . $noaa_files . "]");

// Collect all the files
$dirinf = getThisDir($noaa_files, 0);

// How many did we find??
$indexCount = count($dirinf);

// Reverse sort them so they are newest first

for($index=0; $index < $indexCount; $index++) {
    // Exclude . and .. 
    if (substr("$dirArray[$index]", 0, 1) != ".") {
        // Only want to collect files with the noaa_name in it...
        dbmsg("Compare [" . $dirinf[$index] . " With " . $noaa_name . "]");
        if (substr($dirinf[$index],0, strlen($noaa_name) ) == $noaa_name ){
            // Matched, then added it to the found array as it is...
            $found[] = $dirinf[$index];

// Get current month
$month = date("n");

// Get monthname 
$monthname = $mnthname[$month -1];

// Get current year.
$year =  date("Y");

// Output begining of form

echo '
    Other Available Reports:

    <form style="display: inline; margin: 0;" method="get" action="parse_noaa_date.php" >
    <select name="date">';

// Output Current Month
echo '<option value="' . $year . $month . '">' . $monthname . ' ' . $year . '</option>' . "\n";

// Look for which files to display as an option

foreach ($found as $value ) {
    // Get the 16-21 values
    $option = substr($value, 16,6);
    // Get the month from the filename
    $month = substr($value,20,2);
    // Create the datename string
    $datename = $mnthname[ $month -1  ] . ' ' . substr($value,16,4);
    // Now output it as a value
    echo '<option value="' . $option . '">' . $datename . '</option>' . "\n";

// We are done so close the option and add a submit button
echo '</select><input type="submit" value="Go" /></form>';

// end of modoule

// Supporting functions not found in this example but needed...

// Internal TNET Function - dbmsg (Debug Message)
// Displays Debug Message if $DEBUG is set
function dbmsg ($msg){
    global $SITE, $DEBUG;
    if ($DEBUG) {
        echo 'DEBUG: ' . $msg . '
' . "\n";

// Internal TNET Function - getThisDir
// Collects files for the directory provided and
// sorts if sort flag is set
function getThisDir ($directory, $sort) {
    dbmsg("Opening [" . $directory . "] sortflg = " .$sort );
    $myDirectory = opendir($directory);
    while($entryName = readdir($myDirectory)) {
        dbmsg("Found File: " . $entryName );
        $dirArray[] = $entryName;
    if ($sort)

Hi TNETWeather, thanks for that i appreciate it. Will give it a good look at. I have used arrays before when i did java but i just find them a bit of pain. As you say they are your friend and i agree they are quite useful for many things.

Well im just going to start fixing them now. As long as they do the job at the mo’ then update them as i go along with the “fancier” features.


hi again.

I need some more help with my scripts. Im updating my site and its almost ready to go but ive being trying to get my scripts finished off for ages and its taking too much time. Even though they are simple im not very good with php or programming in general. Could someone please have a look at them for me, you will spot how its meant to work at the moment. The messages are not displaying at the correct point, im assuming this is due to my dodgy conditional statements.

You can find them both on this page: .

Its the Archived & Current Monthly Reports & Archived & Current Yearly Reports that need to be fixed.

You can find the 2 scripts attached.

On this page also , after a person has selected the video and clicked submit i need the page to jump back down to the bottom where the selector and video player is. How do i do this.

Many thanks

prev-monthly-rep.php.txt (3.86 KB)

prev-yearly-rep.php.txt (2.79 KB)