一千萬個為什麽

搜索

在mysql if語句中遇到麻煩

我只是想簡化之前我正在做的事情,有多個php文件列出所有數據。 這是我的html表單:

                                     <table   border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D3D3D3">
<tr>
<form name="formcheck" method="post" action="list.php" onsubmit="return formCheck(this);">
<td>
<table  border="0" cellpadding="3" cellspacing="1" bgcolor="">
<tr>

<td  colspan="16" height="25"  style="background:#5C915C; color:white; border:white 1px solid; text-align: left">List Students</td>
</tr>
<tr>
<td width="30" height="35">*List:</td>
<td width="30"><input name="specific" type="text" id="specific" maxlength="25" value="">
</td>

<td>*By:</td>
<td>
    </td></td>
    </tr>
    <tr>
   <td width="10"><input  align="right" type="submit" name="Submit" value="Submit" > </td>
</tr>
</form>
</table>

And here's the form action:

<?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("school", $con);

$gyear= $_POST['general'];



if ("YEAR"==$_POST['general']) {
$result = mysql_query("SELECT * FROM student WHERE YEAR='{$_POST["specific"]}'");


echo "<table border='1'>
<tr>
<th>IDNO</th>
<th>YEAR</th>
<th>LASTNAME</th>
<th>FIRSTNAME</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
   echo "<tr>";
   echo "<td>" . $row['IDNO'] . "</td>";
  echo "<td>" . $row['YEAR'] . "</td>";
  echo "<td>" . $row['LASTNAME'] . "</td>";
    echo "<td>" . $row['FIRSTNAME'] . "</td>";


  echo "</tr>";
  }
echo "</table>";
}

mysql_close($con);
?>

請幫助,我如何將YEAR(mysql數據庫中的列)和選項框(常規)等同起來。

if ("YEAR"==$_POST['general']) 

如果我錯了,請糾正我。

最佳答案

if ("YEAR"==$_POST['general']) {
  $result = mysql_query("SELECT * FROM student WHERE date_format(YEAR, '%Y')='{$_POST["specific"]}'");

轉載註明原文: 在mysql if語句中遇到麻煩