I have stats on tennis players M&F as far as rankings, name, location, image etc in a mysql DB and excel cvs.
i want to create a page where I can have a form asking for M or F and rank and then have the various stats like handedness, country, image etc come up on the page without refreshing.
I want to do it the quickest way but in the most current type of language or DB or structure or framework.
you need a server to handle the form submit request
form submit is via XMLHTTPRequest to avoid a page reload - server gets request and queries db to get data - server converts data to json - server sends json data back to browser - browser javascript uses json data to update page html
So I assume you know how to connect to the mysql DB and create a query to select records?
If so, then once you get your records with something like below (I am using the PDO class for the connection to the DB). This code will
<?php
// this code assumes you are properly connected to the mysql DB and the connection
// is called "$DBcon" and you have a DB table named "tennis_stats_tbl" in your DB.
$query = "SELECT * FROM tennis_stats_tbl";
// would need to add a WHERE clause to filter out data gender and rank received
// from the request/post)
$stmt = $DBcon->prepare($query);
$stmt->execute();
$tennisStats= array(); // initialize an array to inserts query results
// now loop through each row of data and insert into $tennisStats array
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
$tennisStats['TennisStats'][] = $row;
}
$jsonData = json_encode($tennisStats);
// the above assign a JSON string of the data which can be returned to the client
// requesting this page
?>
Now, you just need to create the HTML (form used to provide the query parameters gender and rank), CSS (to format the page), and JavaScript to work get the form data to submit the request to the php file containing the code above. If you are not familiar with HTML, CSS, or JavaScript, then take advantage of the training which Free Code Camp provides to learn how to use HTML, CSS, and JavaScript for creating your website.
I know how to do this in PHP but I am trying to learn the new technologies.
this is how I do the whole thing in PHP and mysql:
I webscrape the data into a csv file. Then I upload it to hosting site via phpadmin to convert it to mysql. Then I write the sql and php code to do the crud.
But what I am not understanding is how to do this in node or whatever.
I keep reading about having to download stuff to my laptop and do all sorts of command lines to set it up. But isn’t here some place that this is all done for you like is done for a php website?
Do hosting services like godaddy etc have a setup where I can do this as easily as I can with PHP?
Even in PHP I almost never set it up on my laptop. I just do it on the hosting service.
And say I wanted to collaborate with someone via github to do a PHP project would we hammer it out on github THEN ftp it up to the hosting
Do you use an offline program to webscrape the data? Why not webscrape using php and instead of creating a csv file, just import the data directly into your mysql database? There is no need to upload via phpadmin. That is just an extra step. I pull data off websites all the time and incorporate into a db of some sort.
Still learning node myself, so I can not help you there. I would just do it all iin PHP (without using the proprietary software) until you learn node. If you can do it in PHP, it will be similar in node once you learn it.
these are different things - you’re doing some backend work to populate a db - that is relatively straightforward - now you want a web app to use the db - this requires a webserver - writing a server is actually quite easy in node - setting it up needs a bit of server admin - I prefer postgres over mysql - it has the best of both worlds - a relational db with good json support
you could try a cloud database like firebase if you want to avoid writing a server
btw you should never have to pay for webscraping - it usually can be done in a few lines of bash