The first thing to do is make a connection to your MySQL database:
The next php file I wrote was the file that checks which tables are in my database, and if it doesn’t find one called ‘runs’, it creates it.
Now, the very cool thing about php, is having these little modular pieces of code spread across different files and being able to use them in your main code. Note that in
create_db.php, it uses the variable
$link, which was defined in
connection.php. So, these two files would only work if they are called in order. You call and execute php scripts by using the keyword ‘include’. So from another php file we would do the following:
<?php include ‘connection.php'; include ‘create_db.php'; ?>
<div>. I include one at random here:
Here the function
updategraph accepts two arguments.
slider is the new value of the slider bar, and
id is the id of the slider bar.
id is the name of the php file without the ‘.php’ bit. To send the value of the slider bar to php we use a
$.ajax function which use. Here the type is set to
POST the url is
id + ‘.php’, the data is the value of slider bar and here we call it
runs. There is then a success function which deals with the output of the php call.
My success function might seem strange, as I could have just used the
eval() function to convert the php string back to an array, but I read a lot about being careful using this function when dealing with MySQL queries as they can be used to corrupt data. This is probably overly cautious, but I
replace in order to get to the data. I then insert this data in the google visualisation API call.
In the php file, we scoop up that variable in with the
$_POST['runs'] line. I have then used
I really enjoyed working on this project and have learnt some new skills. I hope this article has helped you with some of the basics of this process.