Visualizzazione dei risultati da 1 a 5 su 5

Hybrid View

  1. #1
    Utente di HTML.it L'avatar di clasku
    Registrato dal
    Aug 2006
    Messaggi
    3,197
    Forse perché in quella con il foreach hai un id per ogni joke, nell'altra devi cancellare tutto per un determinato autore

  2. #2
    Quote Originariamente inviata da clasku Visualizza il messaggio
    Forse perché in quella con il foreach hai un id per ogni joke, nell'altra devi cancellare tutto per un determinato autore
    Non credo perché in quella con il foreach ho diversi id per ogni joke perché ogni joke può appartenere a più categorie. jokecategory, per capirci mette in relazione i joke e le category e individua a quale categoria appartiene ogni joke.

    Ecco qui il codice sql:

    codice:
    CREATE TABLE joke (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        joketext TEXT,
        jokedate DATE NOT NULL,
        authorid INT
    ) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB;
    
    CREATE TABLE author (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(255),
        email VARCHAR(255)
    ) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB;
    
    CREATE TABLE category (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(255)
    ) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB;
    
    CREATE TABLE jokecategory (
        jokeid INT NOT NULL,
        categoryid INT NOT NULL,
        PRIMARY KEY (jokeid, categoryid)
    ) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB;
    
    # Sample data
    # We specify the IDs so they are known when we add related entries
    
    INSERT INTO author (id, name, email) VALUES
    (1, 'Kevin Yank', 'thatguy@kevinyank.com'),
    (2, 'Joan Smith', 'joan@example.com');
    
    INSERT INTO joke (id, joketext, jokedate, authorid) VALUES
    (1, 'Why did the chicken cross the road? To get to the other side!', '2012-04-01', 1),
    (2, 'Knock-knock! Who\'s there? Boo! "Boo" who? Don\'t cry; it\'s only a joke!', '2012-04-01', 1),
    (3, 'A man walks into a bar. "Ouch."', '2012-04-01', 2),
    (4, 'How many lawyers does it take to screw in a lightbulb? I can\'t say: I might be sued!', '2012-04-01', 2);
    
    INSERT INTO category (id, name) VALUES
    (1, 'Knock-knock'),
    (2, 'Cross the road'),
    (3, 'Lawyers'),
    (4, 'Walk the bar');
    
    INSERT INTO jokecategory (jokeid, categoryid) VALUES
    (1, 2),
    (2, 1),
    (3, 4),
    (4, 3);

    Più pratica in futuro...

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 © 2026 vBulletin Solutions, Inc. All rights reserved.