9
I’m on a project to build a social network with the @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 on Mysql and so I went after!
I read about concept, tutorials and etc, however, in none of them (nor in google) I found what I need: Update the fields within Mysql itself.
For example: when a user registers on the system I call a Procedure that updates/inserts in the compatibility table the amount that exists between him and other users.
In PHP I know how to do, but we have already left a lot of weight on it and try to see if it would be possible to do this in mysql, as I said earlier...
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 the errors of Portuguese, of agreement and redundancies in the sentences, unfortunately I had to write this topic with a huge headache)
Good guy, that’s just what I needed! vlw! =)
– MateusDemboski