收音机按钮获取数据

时间:2015-02-27 04:15:32

标签: php jquery radio-button

我正在尝试使用两个不同的单选按钮来排序数据。我有数据,但单选按钮不起作用。我也没有任何错误或任何错误,所以我完全不知所措......

非常感谢任何帮助!

<?php 
  session_start();
  $user = $_SESSION['user']; 
  if(!isset($user)){
    header("Location:login.php");
  }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>WDD 420 Course Project</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="_js/jquery-1.7.2.min.js"></script>
<script src="_js/nav1.1.min.js"></script>
<script>
$(document).ready(function() {
 $("#nav_bar").navPlugin({
   'itemWidth': 150,
   'itemHeight': 30,
   'navEffect': "slide",
   'speed': 250
 });
});
</script>
</head>
<body>
<div class="container">
  <div class="header">
    <div class="logo">
      <a href="index.html"><img src="images/mylogo.jpg" alt="Logo for    the Virginia Easter Seals' spring marathon. Home link"></a>
    </div>
    <nav id="navigation">
    <ul id="nav_bar">
    <li><a target="_self" href="index.html">Home </a></li>
    <li><a target="_self" href="signup.php">Sign Up</a></li>
    <li><a target="_self" href="refer.php">Refer A Friend</a></li>
    <li><a target="_self" href="login.php">Login</a></li>
    <li><a target="_self" href="report.php">Report</a></li>
    </ul>
    </nav>
  </div>

 <div class="content">
  <form method="post" name="form4" id="form4" action="">
  <label for="submit_sort">Sort By: </label></th><td>
          <input name="submit_sort" type="radio" id="lname" value="lname">
          <label for="lname">Last Name</label>
          <input name="submit_sort" type="radio" id="distance" value="distance">
          <label for="distance">Distance</label>
      </form>
  <table width="100%" cellpadding="5">
    <tr><th>First Name:</th><th>Last Name:</th><th>Email:</th><th>Distance:</th></tr>
    <?php
    include('inc/dbuser.php');
    $select = "SELECT fname, lname, email, distance FROM runner ORDER BY lname";
    $result = mysqli_query($lrconnect, $select) or die ('Oops! '.mysqli_error($lrconnect));

    if(isset($_POST['submit_sort'])){
        $radio = $_POST['submit_sort']; 
        if($radio =='lname'){
          $select = "SELECT fname, lname, email, distance FROM runner ORDER BY lname";}
        else if($radio =='distance'){
          $select = "SELECT lname, fname, email, distance FROM runner ORDER BY distance";}
          $result = mysqli_query($lrconnect, $select) or die('Invalid Query! '.mysqli_error($lrconnect));
        }

      while($row = mysqli_fetch_assoc($result)) {
        echo '<tr><td>'.$row['fname'].'</td>';
        echo '<td>'.$row['lname'].'</td>';
        echo '<td>'.$row['email'].'</td>';
        echo '<td>'.$row['distance'].'</td></tr>';
      }

    ?>
  </table>
  </div>

1 个答案:

答案 0 :(得分:2)

发布此内容以解决问题。

您没有提交按钮,因此请在表单中添加以下内容:

<input type="submit" name="submit" value="Submit">