我有一个名为forms1的数据库和一个名为demo
表中的字段是ID,Autore,Titolo,cit
我希望我有第一行,使我能够对查询检索到的字母数字值进行排序,例如
如何修改我的代码?这是 cerca2.php:
<style>
br {margin-bottom:-10px;}
</style>
<form action="cerca2.php" method="post">
<b>Nome</b> <input type="text" name="Nome">
<b>Numero </b><input type="text" name="Numero">
<b>city </b><input type="text" name="city">
<input type="Submit">
</form>
<style>
tr:nth-of-type(odd) { background-color: AZURE; }
tr:nth-of-type(even) { background-color: CYAN; }
</style>
<style>
tr:hover{background-color<img src="images/smilies/biggrin.gif" border="0" alt="">EEPSKYBLUE;}
</style>
<?php
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='auto' bgcolor=”#7FFFD4″> <i>ID<i/></td>";
echo "<td width='auto' > <i>Nome<i/></td>";
echo "<td width='auto' ></td>";
echo "<td ></td>";
echo "</tr>";
define('DB_NAME', 'forms1');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can't use ' . DB_NAME . ': ' . mysql_error());
}
$Nome = str_replace(' ', '%', $_POST['Nome']);
$Numero = str_replace(' ', '%', $_POST['Numero']);
$city = str_replace(' ', '%', $_POST['city']);
$arNome = str_split($Nome);
$arNumero = str_split($Numero);
$arcity = str_split($city);
$Nome='';
foreach ($arNome as $value)
{
if ($value=='%') continue;
$Nome.=$value.'%';
}
$Numero='';
foreach ($arNumero as $value)
{
if ($value=='%') continue;
$Numero.=$value.'%';
}
$city='';
foreach ($arcity as $value)
{
if ($value=='%') continue;
$city.=$value.'%';
}
$sql = mysql_query("SELECT * FROM demo WHERE Autore LIKE '%$Nome%' AND Titolo LIKE '%$Numero%' AND cit LIKE '%$city%' ORDER BY Autore") or die(mysql_error());
while($row=mysql_fetch_array($sql)){
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $row[0] . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". "</td>";
echo "<td width='auto'>" . " ". "<i>" . $row[2] . "<i/>". " " . "</td>";
echo "<td width='auto'>" . " ". "<i>" . $row[3] . "<i/>". " " . "</td>";
echo "</tr>";
}
mysql_close();
?>
当我单击时,我会单击Nome和其他th(ID 除外)以重新排序值字母数字 AZ 或 ZA,反之亦然。目前这是我调用查询时 的结果页面(查看上面的代码):
我也会 - 但我不知道该怎么做 - ID 值始终从 1 开始,并根据每次我从th标签进行查询或排序时检索到的 x 值的数量以数字顺序继续。
相反,在我的情况下,总是取决于它所代表的价值。从图中可以看出,数字以随机顺序出现。在这里,我不想要这个。