Drawings Photos Recordings Train Info.
crossbuck

Valid HTML!

Valid CSS!

Page Code

This page explains the form used to enter the photo search. For the page displaying the results, see the code for the Photo Search Results page.

Photo Search Enter Page

The "Photo Search Enter" page uses a form to send a query to the "Photo Search Results" page, which then presents photos based on what was filled in the form. The following shows the code used for the form on the "Photo Search Enter" page. All parts of the code are included, so when attached together in a string they create the form's entire code.

To avoid presenting variables that are normally hidden, some variable names have been changed.

Database connect

Before the form is presented, a connection needs to be made to the database. The following code connects to the database server.

<?php
$connect = mysql_connect("host_address","user","password");
if (!$connect)
	die('Could not connect');

Once a connection has been made to the server, the database needs to be selected.

mysql_select_db("database_name", $connect);

Form Fields

There are two sets of form fields: one for locomotives and one for rolling stock.

if ($_GET['locorsselect'] != "Locomotives" || $_GET['locorsselect'] != "Rolling Stock")
	$_GET['locorsselect']="Locomotives";

Switching between "Locomotives" and "Rolling Stock"

To navigate between locomotive and rolling stock photos, the terms "Locomotives" and "Rolling Stock" are displayed in a list.

if ($_GET['locorsselect'] == "Locomotives")
	print '<ul>
	<li><b>Locomotives</b></li>
	<li><a href="mephotosearchenter.php?locorsselect=Rolling+Stock">
		Rolling Stock</a></li>
	</ul>';

if ($_GET['locorsselect'] == "Rolling Stock")
	print '<ul>
	<li><a href="mephotosearchenter.php?locorsselect=Locomotives">
		Locomotives</a></li>
	<li><b>Rolling Stock</b></li>
	</ul>';

Form Start

The form action is the "Photo Search Results" page, called 'mephotosearchresults.php'. The value of 'locorsselect' is needed for that page, so it is included in the form as a hidden value.

print '<form action="http://trainiax.net/mephotosearchresults.php">
<input type="hidden" name="result_locors" value="' . $_GET['locorsselect'] . '">';

Reporting Marks

Locomotives and rolling stock are stored in two different tables. Table_1 stores locomotives, and Table_2 stores rolling stock. Once the value of locorsselect is determined, the form presents a select list of all the reporting marks found in either table. The following code is for this select list.

print '<h3>' . $_GET['locorsselect'] . ' - Reporting Marks</h3>';
print '<select name="selectmark">
<option>All Marks</option>
<option value="All Marks"></option>';

//Selection of Locomotive Mark
if ($_GET['locorsselect'] == "Locomotives")
	{
	$loco_marklist = mysql_query("SELECT DISTINCT Mark 
		FROM Table_1 
		ORDER BY Mark");
		
	while($loco_markrow=mysql_fetch_array($loco_marklist))
		{
		//the following three lines are for number count
		$count_locomark=$loco_markrow['Mark'];
		$count_locoquery=mysql_query("SELECT * 
			FROM Table_1 
			WHERE Mark='$count_locomark'");
		$count_lococount=mysql_num_rows($count_locoquery);
		
		print '<option value="' . $loco_markrow['Mark'] . 
			'">' . $loco_markrow['Mark'] . 
			'&nbsp; (' . $count_lococount . ')</option>';
		}
	}

//Selection of Rolling Stock Mark
if ($_GET['locorsselect'] == "Rolling Stock")
	{
	$rstock_marklist = mysql_query("SELECT DISTINCT Mark 
		FROM Table_2 
		ORDER BY Mark");
		
	while($rstock_markrow=mysql_fetch_array($rstock_marklist))
		{
		$count_rstockmark=$rstock_markrow['Mark'];
		$count_rstockquery=mysql_query("SELECT * 
			FROM Table_2 
			WHERE Mark='$count_rstockmark'");
		$count_rstockcount=mysql_num_rows($count_rstockquery);
		
		print '<option value="' . $rstock_markrow['Mark'] . 
		'">' . $rstock_markrow['Mark'] . 
		'&nbsp; (' . $count_rstockcount . ')</option>';
		}
	}
	
print '</select><br>';

Types of Locomotives or Rolling Stock

Following a similar method as with the marks, a select list is created of all types of locomotives or rolling stock found in either Table_1 or Table_2.

print '<h3>Types of ' . $_GET['locorsselect'] . '</h3>';
print '<select name="selecttype">
<option selected>All Types</option>
<option value="All Types"></option>';

//Selection of Locomotive Type
if ($_GET['locorsselect'] == "Locomotives")
	{
	$loco_typelist = mysql_query("SELECT DISTINCT Builder,Type 
		FROM Table_1 
		ORDER BY Builder, Type");
		
	while($loco_typerow=mysql_fetch_array($loco_typelist))
		{
		print '<option value="' . $loco_typerow['Type'] . '">' . 
			$loco_typerow['Builder'] . ' ' . 
			$loco_typerow['Type'] . '</option>';
		}
	}

//Selection of Rolling Stock Type
if ($_GET['locorsselect'] == "Rolling Stock")
	{
	$rstock_typelist = mysql_query("SELECT DISTINCT Type 
		FROM Table_2 
		ORDER BY Type");
		
	while($rstock_typerow=mysql_fetch_array($rstock_typelist))
		{
		print '<option>' . $rstock_typerow['Type'] . '</option>';
		}
	}
	
print '</select><br>';

Date

The database has the year, month and day listed in separate columns. The date selection list presents all combinations of year, month and day for either locomotives or rolling stock.

print '<h3>Dates</h3>
<select name="selectdate">
<option selected>All Dates</option>
<option value="All Dates"></option>';

if ($_GET['locorsselect'] == "Locomotives")
	{
	$list_date = mysql_query("SELECT DISTINCT Year, Month, Day 
		FROM Table_1 
		ORDER BY Year, Month, Day");
	}
	
if ($_GET['locorsselect'] == "Rolling Stock")
	{
	$list_date = mysql_query("SELECT DISTINCT Year, Month, Day 
		FROM Table_2 
		ORDER BY Year, Month, Day");
	}
	
while($row_date = mysql_fetch_array($list_date))
	{
	print '<option value="' . $row_date['Year'] . ',' . 
		$row_date['Month'] . ',' . $row_date['Day'] . '">' . 
		$row_date['Year'] . '-' . $row_date['Month'] . '-' . 
		$row_date['Day'] . '</option>';
	} 
print '</select>';
?>

Other Form Inputs

The remaining form inputs are simple html and serve to select photo type and result pages.

<h3>Type of photos</h3>

<input type="radio" name="selectphototype" value="All Photos" checked 
	id="id_All"><label for="id_All">All Photos</label><br>
	
<input type="radio" name="selectphototype" value="R" 
	id="id_R"><label for="id_R">Roster Photos Only</label><br>
	
<input type="radio" name="selectphototype" value="D" 
	id="id_D"><label for="id_D">Detail Photos Only</label><br>
	
<input type="radio" name="selectphototype" value="S" 
	id="id_S"><label for="id_S">Scenic Photos Only</label><br>

<h3>Results per page</h3> 

<input type="radio" name="selectrowsperpage" value="10" 
	id="rows10"><label for="rows10">10</label><br>
	
<input type="radio" name="selectrowsperpage" value="20" checked 
	id="rows20"><label for="rows20">20</label><br>
	
<input type="radio" name="selectrowsperpage" value="50" 
	id="rows50"><label for="rows50">50</label><br>
	
<input type="radio" name="selectrowsperpage" value="100" 
	id="rows100"><label for="rows100">100</label><br>
	
<br>
<input value="Search Photos" type="submit">
<input value="Reset" type="reset">
</form>
Copyright © Michael Eby - Page code last updated 2010-07-18