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

Asked

Viewed 67 times

1

I am wanting to set up a system to display the most popular images of my application. Today I list these images simply but efficiently: the folders become categories and list the images from within the folder. Then, the application reads the image link as the server url + category + image name.

To build a popularity system I thought of counting how many times someone clicked the share button and send this information to a Mysql database next to the category and the 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 that? They know of an open source project that has something similar to try to learn?

  • You need to create a webservice, when clicking share, the app must send the name(unico) or hash photo(or some unique identifier) for the webservice save in comics mysql server. In the bd you need to have a table that contains the identification of the photo, category and the sharing Qtd.

1 answer

1


I thought the following:

You create a table compartilhamento, relating imagem and usuario. The table compartilhamento would be unique in the columns imagem_id and usuario_id, making it impossible for any user to share the image more than once.

The query to find the most shared images would be something like this:

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

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

GET /imagens/compartilhadas

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

[
    {
        "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.

  • 1

    Only one was missing ORDER BY and a LIMIT to take the most shared :)

  • @Luke well noticed! I put the ORDER BY but the LIMIT varies greatly according to implementation :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.