I have a database called forms1 and a table named demo
The fields in the table are ID, Autore, Titolo, cit
I wish I had a first line that gives me the ability to sort alphanumeric values that are retrieved by the query, such as
How can i modify my code?
This is 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();
?>
I would click on Nome and other th (except ID) to reorder the values alphanumeric AZ or ZA viceversa when i click. At the moment this is my result page (look code above) when i call a query:
I would, too - but I do not know how to do - that the ID value always start from 1 and continue in numerical order according to the number of x values retrieved every time I make a query or sort from th tag.
In my case, instead, is always dependent on the value it represents.
You see it from the picture that the numbers appear in random order.
Here, I do not want this.