Creazione tabelle
Query:codice:CREATE TABLE `defaultds`.`users` ( `idUtente` int(10) unsigned NOT NULL auto_increment, `name` varchar(45) default NULL, PRIMARY KEY (`idUtente`) ) ENGINE=InnoDB AUTO_INCREMENT=9540 DEFAULT CHARSET=latin1; CREATE TABLE `defaultds`.`positions` ( `idUtente` int(10) unsigned NOT NULL auto_increment, `timeInserted` timestamp NOT NULL default CURRENT_TIMESTAMP, `latitudine` float NOT NULL, `longitudine` float NOT NULL, PRIMARY KEY USING BTREE (`idUtente`,`timeInserted`), CONSTRAINT `FK_Posizioni_1` FOREIGN KEY (`idUtente`) REFERENCES `users` (`idUtente`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=929 DEFAULT CHARSET=latin1;d
1) select * from users
2) per ogni utente
"select * from Position p where p.idUtente= "+idUtente+" order by timeInserted desc limit 1"
Così ottengo un solo record per quell'utente. su quel record controllo poi latitudine e longitudine. Se va bene inserisco l'utente in un array

Rispondi quotando