I have a simple table
CREATE TABLE `keys` (
`IDkey` int NOT NULL auto_increment,
`username` varchar(50) NOT NULL,
PRIMARY KEY (`IDkey`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
and give out incrementing integer keys 'IDkey' to users as they call in with my webapp. I also store their username in the table.
I have two questions I'm stuck on.
First question: at the moment I am doing the following to give out the key, is there a way to combine this into one query?
INSERT INTO keys VALUES (NULL, '$username');
SELECT IDkey FROM keys WHERE username='$username';
Second Question: the key expires so the same user may return for a new key but this causes a problem because their username is already in the database. Is there a way to write my SELECT query so it returns the most recent record by that user?