OK, I've been learning PHP using Sams teach yourself php in 24 hours. In the end we've created a database for a clubs there events. There is a php page which lets us list all events by date and type. What I have been trying to do is add an additional search to this which adds another parameter of search by event or club name.
The code for the search page is (quite long):
<?php
include("dblib.inc");
include("date.inc");
include("clublib.inc");
if ( isset($actionflag) && $actionflag == "showEvents" )
$session[viewevents] = $form;
elseif ( $session[viewevents] )
$form = $session[viewevents];
else
{
$d_array = getDate( time() );
$session[viewevents][area] = "ANY";
$session[viewevents][type] = "ANY";
$session[viewevents][months] = $d_array[mon];
$session[viewevents][years] = $d_array[year];
}
$range = getDateRange( $session[viewevents][months],
$session[viewevents][years] );
function displayEvents( )
{
global $range, $session, $noom;
$events = getEvents( 0, $range, $session[viewevents][area],
$session[viewevents][type], $noom );
if ( ! $events )
{
print "No events yet for this combination<p>";
return;
}
print "<table border=1>\n";
print "<td><b>Date</b></td>\n";
print "<td><b>Event</b></td>\n";
print "<td><b>Club</b></td>\n";
print "<td><b>Area</b></td>\n";
print "<td><b>Type</b></td>\n";
foreach ( $events as $row )
{
print "<tr>\n";
print "<td>".date("j M Y H.i", $row[edate])."</td>\n";
print "<td><a href=\"viewevent.php?event_id=$row[id]&".SID."\">".
html($row[ename])."</a></td>\n";
print "<td><a href=\"viewclub.php?club_id=$row[eclub]&".SID."\">".
html($row[name])."</a></td>\n";
print "<td>$row[areaname]</td>\n";
print "<td>$row[typename]</td>\n";
print "</tr>\n";
}
print "</table>\n";
}
?>
<head>
<title>View events</title>
</head>
<body>
<?php
include("publicnav.inc");
?>
<h1>View Events</h1>
<p>
<form action="<?php print $PHP_SELF;?>">
<input type="hidden" name="actionflag" value="showEvents">
<input type="hidden" name="<?php print session_name() ?>"
value="<?php print session_id() ?>">
<select name=form[months]>
<?php writeMonthOptions( $range[0] ); ?>
</select>
<select name=form[years]>
<?php writeYearOptions( $range[0] ); ?>
</select>
<select name=form[area]>
<option value="ANY">Any Area
<?php writeOptionList( "areas", $form[area] ) ?>
</select>
<select name=form[type]>
<option value="ANY">Any type of event
<?php writeOptionList( "types", $form[type] ) ?>
</select>
<input type = "submit" value="Change">
</form>
<?php
displayEvents( );
?>
</body>
The functions held in an inc file are:
function getEvents( $club_id=0, $range=0, $area=0, $type=0)
{
global $link;
$query = "SELECT users.name, events.*, areas.area as areaname, types.type as typename ";
$query .= "FROM users, events, areas, types WHERE ";
$query .= "users.id=events.eclub
AND events.area=areas.id
AND events.type=types.id ";
if ( ! empty( $club_id ) && $club_id !="ANY" )
$query .= "AND events.eclub='$club_id' ";
if ( ! empty($range) )
$query .= "AND events.edate >= '$range[0]' AND events.edate <='$range[1]' ";
if ( ! empty($area) && $area != "ANY" )
$query .= "AND events.area='$area' ";
if ( ! empty($type) && $type != "ANY" )
$query .= "AND events.type='$type' ";
$query .= "ORDER BY events.edate";
$result = mysql_query( $query, $link );
if ( ! $result )
die ( "getIDevents fatal error: ".mysql_error() );
$ret = array();
while ( $row = mysql_fetch_array( $result ) )
array_push( $ret, $row );
return $ret;
}
the other functions I don't think matter for this (unless you want them)
If you want to see how this all holds together then take a look here: http://www.nursesnetwork.co.uk/users/join.php
You'd need to join then have a look around. It's pretty basic at the moment, but I just can't get this search think working. Please help me!!!