Salve a tutti ho un problema con un order by (lo so che in giro c'è tanta roba ma non riesco perché a me dia errore).
Ho creato un sistema di gestione dei contatti, funziona tutto perfettamente (inserisco i contatti da csv, li esporto, aggiungo, modifico).
Ora volevo far in modo di poter ordinare le colonne a seconda della scelta ma se provo a far funzionare il seguente script mi da il seguente errore:
	
	
	
		
Come posso risolvere?
	
	
	
		
				
			Ho creato un sistema di gestione dei contatti, funziona tutto perfettamente (inserisco i contatti da csv, li esporto, aggiungo, modifico).
Ora volevo far in modo di poter ordinare le colonne a seconda della scelta ma se provo a far funzionare il seguente script mi da il seguente errore:
		Codice:
	
	You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY Nome_Cognome asc' at line 8
	Come posso risolvere?
		PHP:
	
	<?php
include 'auth.inc.php';
?>
<link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
#error-login {
	clear:left;
	text-align:center;
	position:relative;
	top:50px;
	font-size:18px;
}
#mainform_error {
	height:350px;
	width:800px;
}
/*#intestazione {
	position:fixed;
}*/
</style>
<?php
if ($_SESSION['admin_level'] < 1) {
    header('Refresh: 5; URL=index.php');
   echo '
			<div class="mainform_admin" id="mainform_error" >
			<div>
            <img src="images/logo.png" class="img_main" />
              <h1 class="h1">CRM Verde Profilo</h1>
			</div><br><br><br>
			<div id="error-login">
				<p><strong></strong>Non sei autorizzato a visualizzare la pagina.</strong></p>
				<p>Verrai ora reindirizzato verso la pagina di login. <br><br>Se il tuo browser non ti reindirizza automaticamente, <a href="index.php">clicca qui</a>.</p>
			</div>
			</div>
	';
    die();
}
include 'db.inc.php';
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or 
    die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));
?>
<html>
 <head>
  <title>CRM Verde Profilo</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="Shotcut Icon" href="VPfavicon.ico" />
  <style type="text/css">
   th { background-color: #999;color:#fff;}
   .odd_row { background-color: #EEE; }
   .even_row { background-color: #FFF; }
.mainform_admin {
    width: auto !important;
}
  </style>
 </head>
 <body>
     <div class="mainform_admin" >
     
  
<?php
	if(empty($_GET['ordercampo'])) {
             $ciao = "Nome_Cognome";
	}
	else {
		$ciao = $_GET['ordercampo'];
	}
             if(empty($_GET['order'])) {
             $_GET['order'] = "asc";
			 }
             if($_GET['order']=="asc") {$ordinaVerso = "desc";} 
             if($_GET['order']=="desc") {$ordinaVerso = "asc";} 
             $query = "SELECT
							*
						FROM
							contatti, Lista
						WHERE
							contatti.Lista_id = Lista.Lista_id 
						AND   
							contatti.Lista_id = " . $_GET['Lista_id'] ." ORDER BY ".  $ciao ." ". $ordinaVerso;
							
							
             $result = mysql_query($query) or die(mysql_error()); 
			 
			 
$odd = true; 
while ($row = mysql_fetch_assoc($result)) { 
	$tel = substr($row['Telefono'], 0, 1);
	
	
	if ($tel == 1 || $tel == 2 || $tel == 3 || $tel == 4 || $tel == 5 || $tel == 6 || $tel == 7 || $tel == 8 || $tel == 9) {
		
		$tel_new = "0".$row['Telefono'];	
		
	}
	
	else {
		$tel_new = $row['Telefono'];
	}
	
	$tel2 = substr($row['Telefono'], 0, 1);
	
	
	if ($tel2 == 1 || $tel2 == 2 || $tel2 == 3 || $tel2 == 4 || $tel2 == 5 || $tel2 == 6 || $tel2 == 7 || $tel2 == 8 || $tel2 == 9) {
		
		$tel2_new = "0".$row['Telefono_2'];	
		
	}
	
	else {
		$tel2_new = $row['Telefono_2'];
	}
	
	$fax = substr($row['Fax'], 0, 1);
	
	if ($fax == 1 || $fax == 2 || $fax == 3 || $fax == 4 || $fax == 5 || $fax == 6 || $fax == 7 || $fax == 8 || $fax == 9) {
		
		$fax_new = "0".$row['Fax'];	
		
	}
	
	else {
		$fax_new = $row['Fax'];
	}
	
	$url = substr($row['Sito'], 0, 3);
	
	
	if ($url == 'www') {
		
		$url_new = "http://".$row['Sito'];	
		
	}
	
	else {
		$url_new = $row['Sito'];
	}
	
	
    if ($lista !== $row['Lista']) {
       $titolo_lista = $row['Lista'];
       $lista = $titolo_lista;
	   echo '<div>
            <img src="images/logo.png" class="img_main" />
              <h1 class="h1">CRM Verde Profilo</h1>
              <p class="p_main_contact">Gestione DataBase Contatti | <a href="logout.php" class="logout">Disconnetti</a></p>
              <a href="select_db.php">
                <div class="btn_indietro">
                  <img src="images/back.png" class="img_toolbar" width="24" height="24" />Torna Indietro</div>
              </a>
              <a href="contatti.php?action=add"> 
                <div class="btn_add_user">
                  <img src="images/add_user.png" class="img_toolbar" width="24" height="24" />Aggiungi Nuovo</div>
              </a>
              <h2 class="h2">Contatti</h2>
          </div>';  
	   echo '<table class="table_contact" > 
      <tr> 
       <th colspan="14">'. $titolo_lista .'</th> 
      </tr>'; 
	echo '<tr id="intestazione">';  
	echo '<strong><td class="tb_subtitle">';  
    echo 'Titolo'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Ragione Sociale'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Nome Cognome'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Indirizzo'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Indirizzo alternativo'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'CAP'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Localita'; 
    echo '</td>'; 
	echo '<td class="tb_subtitle">';  
    echo 'Provincia'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Nazione'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Telefono'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Telefono alternativo'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Fax'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Cellulare'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Email'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Sito Web'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Partita IVA'; 
    echo '</td>';
	echo '<td class="tb_subtitle">';  
    echo 'Note'; 
    echo '</td>';
    echo '<td class="tb_subtitle">';  
    echo 'Lista'; 
	echo '</td></strong></tr>';   
    }    
	
    else {
       $titolo_lista = "";
    }
	
	
	$tit = html_entity_decode($row['Titolo']);
	$rag = html_entity_decode($row['Ragione_Sociale']);
	$Nome = html_entity_decode($row['Nome_Cognome']);
	$ind = html_entity_decode($row['Indirizzo']);
	$ind2 = html_entity_decode($row['Indirizzo_2']);
	$loc = html_entity_decode($row['Localita']);
	$mail = html_entity_decode($row['Email']);
	$url = html_entity_decode($row['Sito']);
	$note = html_entity_decode($row['Note']);
	
      
    echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; 
    $odd = !$odd;  
    echo '<td style="width:8%;">';  
    echo $tit;
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $rag;
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $Nome;
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $ind;
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $ind2;
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $row['CAP']; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $loc; 
    echo '</td>'; 
	echo '<td style="width:8%;">';  
    echo $row['Provincia']; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $row['Nazione']; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $tel_new; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $tel2_new; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $fax_new; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $row['Cellulare']; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo '<a href='.'mailto:'.$mail.'>'.$mail.'</a>'; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo '<a href='.$url_new.' target="_blank">'.$url.'</a>'; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $row['Partita_iva']; 
    echo '</td>';
	echo '<td style="width:8%;">';  
    echo $note; 
    echo '</td>';
    echo '<td style="width:8%;">';  
    echo $row['Lista']; 
    echo '</td><td>'; 
    echo ' <a class="btn_grid" href="contatti.php?action=edit&id=' . $row['movie_id'] . '"> [EDIT]</a>';  
    echo ' <a class="btn_grid" href="delete.php?type=contatti&id=' . $row['movie_id'] . '"> [DELETE]</a>'; 
	echo ' <a class="btn_grid" href="duplicate.php?id=' . $row['movie_id'] . '"> [DUPLICATE]</a>'; 
    echo '</td></tr>'; 
}
?>
<a href="admin.php?ordercampo=<?php echo 'Nome_Cognome' ?>&order=<?php echo $ordinaVerso ?>" title="Inverti ordinamento">link</a>
</div>
</body>
</html>