How to create a system to list the most popular images in my application

1

I want to put together a system to display the most popular images in my application. Today I've ready these images in a simple but efficient way: the folders become categories and ready the images from inside the folder. Then the application reads the image link as server url + category + image name.

To set up a popularity system I thought about how many times someone clicked the share button and sent this information to a MySQL database next to the category and image name. So when I do the listing in PHP I can sort them by number of shares.

Can anyone help me how to do this? Do you know of an open source project that has something similar to try to learn?

    
asked by anonymous 30.01.2015 / 11:43

1 answer

1

I thought about the following:

You create a compartilhamento table, relating imagem and usuario . The compartilhamento table would be unique in columns imagem_id and usuario_id , so that no user can share the image more than once.

The query to fetch the most shared images would look something like this:

SELECT nome, count(id) compartilhamentos
FROM imagem
GROUP BY nome
ORDER BY compartilhamentos DESC;

Next you can create a service to search for the most shared images. The URL of this service may be something self-explanatory, something like:

GET /imagens/compartilhadas

And the answer can be an XML or a JSON containing the result of the query in SQL:

[
    {
        "nome": "imagem1.jpg",
        "compartilhamentos": 472
    },
    {
        "nome": "imagem4.jpg",
        "compartilhamentos": 298
    },
    {
        "nome": "imagem5.jpg",
        "compartilhamentos": 112
    },
    {
        "nome": "imagem3.jpg",
        "compartilhamentos": 55
    },
    {
        "nome": "imagem6.jpg",
        "compartilhamentos": 37
    },
    {
        "nome": "imagem2.jpg",
        "compartilhamentos": 14
    }
]

PS: depending on the case the implementation will probably be more complex, but basic idea is more or less what was said above.

    
30.01.2015 / 13:45