I have a Wordpress site which has post ratings stored in the wp\_ratings table, with each rating stored as an individual row. We will be changing the theme soon and need to convert the values stored in wp\_ratings to meta data, which will look as follows:

```
a: 3: {
i: 0;
a: 2: {
    s: 7: "user_id";
    s: 1: "0";
    s: 2: "ip";
    s: 9: "127.0.0.1";
}
i: 1;
a: 2 {
    s: 7: "user_id";
    s: 1: "0";
    s: 2: "ip";
    s: 9: "127.0.0.1";
}
i: 2;
a: 2: {
    s: 7: "user_id";
    s: 1: "0";
    s: 2: "ip";
    s: 9: "127.0.0.1";
}
i: 3;
a: 2: {
    s: 7: "user_id";
    s: 1: "0";
    s: 2: "ip";
    s: 9: "127.0.0.1";
}

```

The total vote value is show by the `a:3` at the beginning of the statement and then there is an individual entry for each rating stored. 

I am not particularly familiar with stored procedures but I want to create a loop that will calculate the total value for each post in wp\_posts `sum(rating_rating)` and then create the meta data into one long string.

I don't really know where to start with this, so if anyone can point me in the right direction, I'd be really grateful.

Thanks