I'm in a social networking project with @RodrigoBorth , and we have the problem of How to index and update a user comparison system ... We were given the idea of working with Stored Procedure in MySQL and then I went back! I read about concept, tutorials and etc, however, in none of them (nor google) I found what I need: Update the fields within MySQL itself . For example: when a user registers in the system I call a Procedure that updates / inserts in the compatibility table the amount that exists between it and the other users. In PHP I know how to do it, but we already left a lot of weight on top of it and would like to see if I could do this in mysql, as I said before ... I currently have the following code in MySQL:
CREATE PROCEDURE insertCompatibility(
IN varUsuario int(11)
)
BEGIN
INSERT INTO compatibilidade (id,alvo,resultado) VALUES (varUsuario, varAlvo, varPorcentagem);
END;
I'd like to do something like this:
CREATE PROCEDURE insertCompatibility(
IN varUsuario int(11)
)
BEGIN
WHILE(linha = SELECT dadosDaTabela FROM usuarios WHERE id <> varUsuario){
//depois eu colocaria o calculo aqui e então:
INSERT INTO compatibilidade (id,alvo,resultado) VALUES (varUsuario, linha[id],resultadoDoCalculo);
}
END;
( Sorry for Portuguese errors, agreement and redundancy in sentences, unfortunately I had to write this topic with a headache)