Php 从mysql中筛选的下拉选择列表

Php 从mysql中筛选的下拉选择列表,php,mysql,Php,Mysql,我在mysql数据库中创建了一个事件列表,我希望用户能够使用下拉列表按位置进行筛选。我已经成功地对下拉框进行了排序,并在表格中显示了数据,但此时选择一个选项并没有任何作用 在另一个问题上,我有多个相同值的位置,因此相同的位置在下拉菜单中多次出现。。。解决这个问题会很好,但首先要让它工作 这是我的代码,我不确定要粘贴多少: <?php require_once('Connections/united_hosting.php'); ?> <?php if (!function_ex

我在mysql数据库中创建了一个事件列表,我希望用户能够使用下拉列表按位置进行筛选。我已经成功地对下拉框进行了排序,并在表格中显示了数据,但此时选择一个选项并没有任何作用


在另一个问题上,我有多个相同值的位置,因此相同的位置在下拉菜单中多次出现。。。解决这个问题会很好,但首先要让它工作

这是我的代码,我不确定要粘贴多少:

<?php require_once('Connections/united_hosting.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
if (PHP_VERSION < 6) {
$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;
}
}

$maxRows_rs_blog = 3;
$pageNum_rs_blog = 0;
if (isset($_GET['pageNum_rs_blog'])) {
$pageNum_rs_blog = $_GET['pageNum_rs_blog'];
}
$startRow_rs_blog = $pageNum_rs_blog * $maxRows_rs_blog;

mysql_select_db($database_united_hosting, $united_hosting);
$query_rs_blog = "SELECT *, DATE_FORMAT(date, '%D %M %Y') AS format_date FROM blog_posts ORDER BY `date` DESC";
$query_limit_rs_blog = sprintf("%s LIMIT %d, %d", $query_rs_blog, $startRow_rs_blog, $maxRows_rs_blog);
$rs_blog = mysql_query($query_limit_rs_blog, $united_hosting) or die(mysql_error());
$row_rs_blog = mysql_fetch_assoc($rs_blog);

if (isset($_GET['totalRows_rs_blog'])) {
$totalRows_rs_blog = $_GET['totalRows_rs_blog'];
} else {
$all_rs_blog = mysql_query($query_rs_blog);
$totalRows_rs_blog = mysql_num_rows($all_rs_blog);
}
$totalPages_rs_blog = ceil($totalRows_rs_blog/$maxRows_rs_blog)-1;
$query_rs_blog = "SELECT *, DATE_FORMAT(date, '%D %M %Y')AS format_date FROM blog_posts ORDER BY `date` DESC";
$rs_blog = mysql_query($query_rs_blog, $united_hosting) or die(mysql_error());
$row_rs_blog = mysql_fetch_assoc($rs_blog);
$totalRows_rs_blog = mysql_num_rows($rs_blog);

mysql_select_db($database_united_hosting, $united_hosting);
$query_rs_news = "SELECT *, DATE_FORMAT(date_posted, '%D %M %Y')AS format_date FROM news_item ORDER BY date_posted DESC";
$rs_news = mysql_query($query_rs_news, $united_hosting) or die(mysql_error());
$row_rs_news = mysql_fetch_assoc($rs_news);
$totalRows_rs_news = mysql_num_rows($rs_news);

mysql_select_db($database_united_hosting, $united_hosting);
$query_rs_events = "SELECT * FROM events ORDER BY `date` ASC";
$rs_events = mysql_query($query_rs_events, $united_hosting) or die(mysql_error());
$row_rs_events = mysql_fetch_assoc($rs_events);
$totalRows_rs_events = mysql_num_rows($rs_events);

$colname_rs_location = "-1";
if (isset($_POST['location'])) {
$colname_rs_location = $_POST['location'];
}
mysql_select_db($database_united_hosting, $united_hosting);
$query_rs_location = sprintf("SELECT location FROM events WHERE location = %s ORDER BY `date` ASC", GetSQLValueString($colname_rs_location, "text"));
$rs_location = mysql_query($query_rs_location, $united_hosting) or die(mysql_error());
$row_rs_location = mysql_fetch_assoc($rs_location);
$totalRows_rs_location = mysql_num_rows($rs_location);
?>


<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post">
<p>
<label for="select">Select:</label>
<select name="select" id="select">
  <?php
do {  
?>
  <option value="<?php echo $row_rs_events['location']?>"<?php if (!(strcmp($row_rs_events['location'], $_POST['']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rs_events['location']?></option>
  <?php
} while ($row_rs_events = mysql_fetch_assoc($rs_events));
$rows = mysql_num_rows($rs_events);
if($rows > 0) {
  mysql_data_seek($rs_events, 0);
  $row_rs_events = mysql_fetch_assoc($rs_events);
}
?>
</select>
<input type="submit" name="submit" id="submit" value="Submit">
</p>
<table width="600" border="1">
<tr>
  <th scope="col">location</th>
  <th scope="col">venue</th>
  <th scope="col">date</th>
  <th scope="col">tickets</th>
</tr>
<?php do { ?>
  <tr>
    <td><?php echo $row_rs_events['location']; ?></td>
    <td><?php echo $row_rs_events['venue_name']; ?></td>
    <td><?php echo $row_rs_events['date']; ?></td>
    <td><?php echo $row_rs_events['tickets_remaining']; ?></td>
  </tr>
  <?php } while ($row_rs_events = mysql_fetch_assoc($rs_events)); ?>
</table>
<p>&nbsp;</p>
</form>
</body>
</html>
<?php
mysql_free_result($rs_blog);

mysql_free_result($rs_events);

mysql_free_result($rs_location);
?>
DISTINCT关键字将允许您获得每个位置只有一个的结果集

if (isset($_POST['location'])) {
    $colname_rs_location = $_POST['location'];
}

确保向该脚本发送POST数据的scipt具有一个名为location的输入字段。目前,提供的代码中的表单使用名称select。

我有多个相同值的位置,因此相同的位置在下拉菜单中多次出现,请在检索位置的sql查询中的select之后添加DISTINCT。关于select不做任何事,这是什么意思?这是否意味着当您从dropbox中选择某个内容时,它不会显示您单击的内容?如果是这种情况,请通过右键单击dropbox检查html语法,然后检查元素,或者如果不可用,只需查看源代码并查看dropbox html是否正确谢谢您的响应。似乎不能得到明确的位工作,我肯定我记得使用过这个,虽然这样会再次检查。重命名表单是否正确?。。。
if (isset($_POST['location'])) {
    $colname_rs_location = $_POST['location'];
}