Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Query per togliere record

    Ciao,
    ho due tabelle la tabella1 con 100 record e la due con 10 entrambe hanno un campo in comune ovvero l'id. Dovrei realizzare una query che tolga i record della tabella2 dalla 1. Come si può fare?

  2. #2
    codice:
    $query = "SELECT id FROM table_2";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result))
         {
            $queryDel = "DELETE FROM table_1 WHERE id = '$row[id]'";
            mysql_query($queryDel);
         }
    Ciao!

  3. #3
    Non mi sono spiegato scusate voglio visualizzare la tabella1 senza i valori della tabella2 che sono presenti anche nella tabella1. Ora è più chiaro?

  4. #4
    Codice PHP:
    $query "SELECT id FROM table_2";
    $result mysql_query($query);
    while (
    $row mysql_fetch_array($result))
         {
            
    $tabella_2[] = $row['id'];
         }
    $query "SELECT * FROM table_1";
    $result mysql_query($query);
    while (
    $row mysql_fetch_array($result))
         {
            if (!
    in_array($row['id'], $tabella_2))
              {
                 
    // Se l'id non è presente nell'altra tabella
                 
    $echo 'l\'id ' $row['id'] . ' non è presente
                        nell\'altra tabella'
    ;
              }
            else
             {
                 
    $echo 'l\'id ' $row['id'] . ' è presente
                        nell\'altra tabella'
    ;
             }
         } 
    Ciao!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.