sort rows of html table - mysql
<p>I have a database called <strong>forms1</strong> and a table named <strong>demo</strong><br>
The fields in the table are <strong>ID</strong>, <strong>Autore</strong>, <strong>Titolo</strong>, <strong>cit</strong></p>

<p>I wish I had a first line that gives me the ability to sort alphanumeric values ​​that are retrieved by the query.<br>
<strong>For sort i mean this</strong>:<br> <a href="http://stackoverflow.com/questions/3489783/how-to-sort-rows-of-html-table-that-are-called-from-mysql">How to sort rows of HTML table that are called from MySQL</a></p>

<p>My problem is adapt code for my situation.
This is <strong><em>cerca2.php</em></strong>:</p>

<pre><code>&lt;style&gt;
br {margin-bottom:-10px;}
&lt;/style&gt;

&lt;form action="cerca2.php" method="post"&gt;
&lt;b&gt;Nome&lt;/b&gt;&amp;nbsp;&lt;input type="text" name="Nome"&gt;&amp;nbsp;&amp;nbsp;
&lt;b&gt;Numero&amp;nbsp;&lt;/b&gt;&lt;input type="text" name="Numero"&gt;&amp;nbsp;&amp;nbsp;
&lt;b&gt;city&amp;nbsp;&lt;/b&gt;&lt;input type="text" name="city"&gt;&amp;nbsp;&amp;nbsp;
&lt;input type="Submit"&gt;
&lt;/form&gt;

&lt;style&gt;
tr:nth-of-type(odd) { background-color: AZURE; }
tr:nth-of-type(even) { background-color: CYAN; }
&lt;/style&gt;
&lt;style&gt;
tr:hover{background-color:DEEPSKYBLUE;}
&lt;/style&gt;

&lt;?php

echo "&lt;table border='1' style='border-collapse: collapse;border-color: silver;'&gt;";  
echo "&lt;tr style='font-weight: bold;'&gt;";  
echo "&lt;td width='auto' bgcolor=”#7FFFD4″&gt;&amp;nbsp;&lt;i&gt;ID&lt;i/&gt;&lt;/td&gt;";  
echo "&lt;td width='auto' &gt;&amp;nbsp;&lt;i&gt;Nome&lt;i/&gt;&lt;/td&gt;";
echo "&lt;td width='auto' &gt;&lt;/td&gt;";
echo "&lt;td &gt;&lt;/td&gt;";
echo "&lt;/tr&gt;";

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());


$i = 0; while($row=mysql_fetch_array($sql)){
        $i++;
        echo "&lt;tr&gt;";
        echo "&lt;td width='auto' bgcolor=”#FF0000 &amp;#8243;&gt;" . "&amp;nbsp;". "&lt;b&gt;"  . $i . "&amp;nbsp;". "&lt;b/&gt;". "&lt;/td&gt;";
        echo "&lt;td width='auto'&gt;" . "&amp;nbsp;" . $row[1] . "&amp;nbsp;" . "&lt;/td&gt;";
        echo "&lt;td width='auto'&gt;". "&lt;/td&gt;";
        echo "&lt;td width='auto'&gt;" . "&amp;nbsp;". "&lt;i&gt;" . $row[2] . "&lt;i/&gt;". "&amp;nbsp;" . "&lt;/td&gt;";     
        echo "&lt;td width='auto'&gt;" . "&amp;nbsp;". "&lt;i&gt;" . $row[3] . "&lt;i/&gt;". "&amp;nbsp;" . "&lt;/td&gt;";
        echo "&lt;/tr&gt;";

}

mysql_close();
?&gt;
</code></pre>
