Skip to main content
March 1, 2009
Question

Searchable race results

  • March 1, 2009
  • 1 reply
  • 312 views
Hey everyone.

I'm working on the website for a 5k run and we would like to be able to have participants search for their name within the page. I saw how one company did it here, http://www.compuscore.com/cs2008/july/rwjhosp1.htm. I would like to be able to do this exact thing for my site. I'm very new to javascript and PHP etc, but great at HTML. If anyone can help me out that'd be great!

Thanks so much!

This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

DwFAQ
Participating Frequently
March 1, 2009
Heya Ryan,

Store info in a database table then create a form with ids for text field first_name, last_name, submit with form action to results.php

In results.php create three conditional regions with MySQL queries for connection to your db and filter according to parameters sent from form; One conditional region if no last name is sent in the search, another conditional region for if not first name is sent in the search, and the last conditional region for if no first or last name has been searched for.

So if form with only first name for "jack" submitted no last name entered goes to results.php?first_name=jack&last_name=
which will show conditional query for database where all first names == jack

Form with only last name of "smith" submitted no first name entered goes to results.php?first_name=&last_name=smith
which will show conditional query for db where last names = smith

Form submitted with no first or last name entered will go to results.php?first_name=&last_name=
which will show conditional query that no parameters have been searched for and as a results all database records are shown.


Your code will look something like this:


<?php
// Show IF No Last Name
if (@$_GET['first_name'] != "" && @$_GET['last_name'] == "") {

// Start MySQL Query
$first_name_filter = "-1";
if (isset($_GET['first_name'])) {
$age_from_filter = $_GET['first_name'];
}

mysql_select_db($database_XXXXXX, $XXXXXX);
$query_filter = sprintf("SELECT * FROM table WHERE first_name=%s",GetSQLValueString($first_name_filter, "text"));
$query_limit_filter = sprintf("%s LIMIT %d, %d", $query_filter, $startRow_filter, $maxRows_filter);
$filter = mysql_query($query_limit_filter, $XXXXXX) or die(mysql_error());
$row_filter = mysql_fetch_assoc($filter);
// End MySQL Query

}
// End IF No Last Name
?>




<?php
// Show IF No First Name
if (@$_GET['first_name'] == "" && @$_GET['last_name'] != "") {

// Start MySQL Query
$last_name_filter = "-1";
if (isset($_GET['last_name'])) {
$age_from_filter = $_GET['last_name'];
}

mysql_select_db($database_XXXXXX, $XXXXXX);
$query_filter = sprintf("SELECT * FROM table WHERE last_name=%s",GetSQLValueString($last_name_filter, "text"));
$query_limit_filter = sprintf("%s LIMIT %d, %d", $query_filter, $startRow_filter, $maxRows_filter);
$filter = mysql_query($query_limit_filter, $XXXXXX) or die(mysql_error());
$row_filter = mysql_fetch_assoc($filter);
// End MySQL Query

}
// End IF No First Name
?>








<?php
// Show IF No First or Last Name
if (@$_GET['first_name'] == "" && @$_GET['last_name'] == "") {

// Start MySQL Query

mysql_select_db($database_XXXXXX, $XXXXXX);
$query_filter = "SELECT * FROM table";
$query_limit_filter = sprintf("%s LIMIT %d, %d", $query_filter, $startRow_filter, $maxRows_filter);
$filter = mysql_query($query_limit_filter, $XXXXXX) or die(mysql_error());
$row_filter = mysql_fetch_assoc($filter);
// End MySQL Query

}
// End IF No First or Last Name
?>



Hope that helps!