Page 1 of 1
direction needed
Posted: Tue Feb 26, 2008 3:34 am
by kevrelland
i want to filter my results from a query with a drop down menu, which i presume would then reload the same page
but being new i have looked and searched but i don't know which direction to go.
so i need direction
cheers
kevin
Re: direction needed
Posted: Tue Feb 26, 2008 4:56 am
by Christopher
Get the value from the form, sanitize and escape it, and then use it in the SQL query.
Re: direction needed
Posted: Tue Feb 26, 2008 5:09 am
by kevrelland
ok
that went completely over my head then
so i get the name for example from my query into a menu and then post the name to the url and have my query pick up the name to filter the results?
is that right?
a little help please
Posted: Tue Feb 26, 2008 9:21 am
by kevrelland
ok i have spent today working on this an i have managed to get it to work except that when the page is first called there is no data shown, i would like to have all the teams showing
how would i go about getting this to work
Code: Select all
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_fixtures = 23;
$pageNum_fixtures = 0;
if (isset($_GET['pageNum_fixtures'])) {
$pageNum_fixtures = $_GET['pageNum_fixtures'];
}
$startRow_fixtures = $pageNum_fixtures * $maxRows_fixtures;
$colname_fixtures = "-1";
if (isset($_GET['home_team_id'])) {
$colname_fixtures = $_GET['home_team_id'];
}
mysql_select_db($database_torquay_skittles, $torquay_skittles);
$query_fixtures = sprintf("SELECT * FROM fixtures WHERE fixtures.played ='n' AND fixtures.cup_fixture ='n' AND away_team_id = %s or home_team_id = %s ORDER BY fixtures.division_num ASC, fixtures.fixture_date DESC, fixtures.`time` ASC", GetSQLValueString($colname_fixtures, "text"),GetSQLValueString($colname_fixtures, "text"));
$query_limit_fixtures = sprintf("%s LIMIT %d, %d", $query_fixtures, $startRow_fixtures, $maxRows_fixtures);
$fixtures = mysql_query($query_limit_fixtures, $torquay_skittles) or die(mysql_error());
$row_fixtures = mysql_fetch_assoc($fixtures);
if (isset($_GET['totalRows_fixtures'])) {
$totalRows_fixtures = $_GET['totalRows_fixtures'];
} else {
$all_fixtures = mysql_query($query_fixtures);
$totalRows_fixtures = mysql_num_rows($all_fixtures);
}
$totalPages_fixtures = ceil($totalRows_fixtures/$maxRows_fixtures)-1;
mysql_select_db($database_torquay_skittles, $torquay_skittles);
$query_team_names = "SELECT DISTINCT fixtures.home_team_id FROM fixtures ORDER BY fixtures.home_team_id ASC";
$team_names = mysql_query($query_team_names, $torquay_skittles) or die(mysql_error());
$row_team_names = mysql_fetch_assoc($team_names);
$totalRows_team_names = mysql_num_rows($team_names);
$queryString_fixtures = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_fixtures") == false &&
stristr($param, "totalRows_fixtures") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_fixtures = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_fixtures = sprintf("&totalRows_fixtures=%d%s", $totalRows_fixtures, $queryString_fixtures);
?>
<?php $lastTFM_nest = "";?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="CSS/skittles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="763" border="0" cellpadding="0" cellspacing="0" id="fixtures">
<tr>
<td colspan="5">
<form action="<?php $_SERVER["PHP_SELF"]?>" method="get" target="_self">
<select name="home_team_id">
<?php
do {
?>
<option value="<?php echo $row_team_names['home_team_id']?>"><?php echo $row_team_names['home_team_id']?></option>
<?php
} while ($row_team_names = mysql_fetch_assoc($team_names));
$rows = mysql_num_rows($team_names);
if($rows > 0) {
mysql_data_seek($team_names, 0);
$row_team_names = mysql_fetch_assoc($team_names);
}
?>
</select>
<input name="" type="submit" />
</form>
</td>
</tr>
<tr id="team_head">
<td colspan="5" valign="top" id="team_alleyname"><h2>Division
<?php $TFM_nest = $row_fixtures['division_num'];
if ($lastTFM_nest != $TFM_nest) {
$lastTFM_nest = $TFM_nest; ?>
<?php echo $row_fixtures['division_num']; ?>
<?php } //End of Basic-UltraDev Simulated Nested Repeat?>
</h2></td>
</tr>
<tr id="fixture_head">
<td id="date"><strong>Date and Time</strong></td>
<td id="home_team"><strong>Home Team</strong></td>
<td id="versus"></td>
<td id="away_team"><strong>Away Team</strong></td>
<td id="alley"><strong>Alley</strong></td>
</tr>
<?php do { ?>
<tr>
<td id="date"><?php echo date('l, F d, Y',strtotime($row_fixtures['fixture_date'])); ?> at <strong><?php echo $row_fixtures['time']; ?></strong></td>
<td id="home_team"><?php echo $row_fixtures['home_team_id']; ?></td>
<td id="versus">versus</td>
<td id="away_team"><?php echo $row_fixtures['away_team_id']; ?></td>
<td id="alley"><?php echo $row_fixtures['alley']; ?></td>
</tr>
<?php } while ($row_fixtures = mysql_fetch_assoc($fixtures)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($fixtures);
mysql_free_result($team_names);
?>