PHP MySql – Getting data from a database into a HTML Table

Some time ago, about 10 days to be more precise, I have decided to take a better look at PHP and to try to understand why so many people hate it actually. After all, as a VBA developer (or if you do not think that the words VBA and Developer should be next to each other, consider me one of the few guys worldwide somehow still making money with VBA) I do not understand how a language as PHP can be hated. That could be done only from people who have never coded in VBA for a living 🙂

Anyone, let’s start. So, my task for today was to build up a small funny table in a MySql database and to take lines from it. This is pretty much a standard task, but after achieving it with PHP and MySql I felt somehow proud, so I have decided to share it.

Here is the table in mySQL:

mysql_table_languages

If you want to build the same and to try to repeat the exercise (if you really do this, send me a message for your reasons), you may find the sql of the exported table at github.

So, let’s start. How the interface looks like? Here is the answer:

get_data_from_table_html get_data_from_table_php

 

You see, that language number 4, Python is not shown in the table, because I have made less than 150 money with it. How do we achieve this awesome result?

Here is the way:

You need two files (it can be done with one as well, but the code there is a little more complicated) – one php and one htm. In the html file you make a simple form with one button, posting to the php file the value in “money”. In the php file, we take the value, we build up a sql query with it and ask the table in our db to give us the results. For each line in the result we build one line in our table. Pretty much that is all. Nothing complicated. 🙂

Here comes the code, available also in github – here is the php and here is the htm file:

Htm:

Enjoy it! 🙂

About

VBA Developer

Tagged with: , , ,