How to populate table in MySql + Node JS - javascript

I'm trying to create a live search using NodeJS Angular and MySql. I found a tutorial and everything is clear for me except how to populate the database. I found only code for loading content from database.
app.get('/load',function(req,res){
console.log("<== We are going to load data from Table ==>");
connection.query("select * from cfg_demos",function(err,rows,fields){
if(err) throw err;
console.log("<== Data is been loaded. ==>");
res.end(JSON.stringify(rows));
console.log("<== Data is been sent to Client. ==>");
});
});
So how to find this cfg_demos?
There is another file:
app.controller('main_control',function($scope,$http){
load_demos();
function load_demos(){
$http.get("http://localhost:7001/load").success(function(data){
$scope.loaded_demos=data;
})
}
});
But it's also for extracting data from database and putting it to html page.
Files are here. And the demo is here. It isn't an advertisement of course, I'm trying to understand how values from the last webpage appeared and how to populate the table.
Thanks for help!

Related

Scrape CSV data to SQL table using PHP, LOAD DATA from URL with Javascript object, (beginner)

(I'm learning and not a pro, so please excuse any faux pas)
I am aware that the PHP, LOAD DATA function may be what I need, but I can't get to the file behind the Java Object.
I am trying to update a SQL table, i.e. overwrite matching dates, with data from a CSV file from Javascript buttons on one of these websites:
-"Download Data" from https://www.investing.com/rates-bonds/us-10-yr-t-note-historical-data (adjusting dates would be ideal)
-"Download Range" from https://www.barchart.com/futures/quotes/Znh18/price-history/historical
-"Download Spreadsheet" from http://quotes.wsj.com/bond/BX/TMUBMUSD10Y/historical-prices
The data looks something like this
Time,Open,High,Low,"Last Price",Change,Volume,"Open Interest"
02/08/18,121.0781,121.25,120.5313,120.8906,-0.10939999999999,2938115,0
02/07/18,121.2031,121.6094,120.8594,121,-0.48439999999999,2201308,3569670
I have used the http://simplehtmldom.sourceforge.net/ utility to extract individual pieces of data, but that seems laborious if a file exists.
e.g. currently this is my code for finding table data on the WSJ page using the file_get_html() function:
...
// Finds the last cash price
foreach($html->find('span[id=price_quote_val]') as $e){
echo str_replace("/32.","",str_replace(" ",".",$e->plaintext)). ' last cash price<br>';
$field='Last';
$value=str_replace("/32.","",str_replace(" ",".",$e->plaintext));
include('table_update.php');
}
....
Thanks!
Chris
I have read other posts, including:
Save CSV files into mysql database
Importing CSV data using PHP/MySQL

nodejs-angular retrieving data from mongodb

I have been trying to retrieve data from mongodb (i'm using also mongoose) and send it to angular to fill the ng-repeat list with data. I am able to print data on blank page from mongo OR display data in list if i declare exemplary static array with data in a list on webpage but i dont know how to connect it to work with data from mongo. I am new to MEAN stack so please spare me.
Please go through video tutorial of Bucky Robert. Try to create the project from Hello world then you will understand.
Node JS tutorial click here
MEAN STACK tutorial: click here
First Create RestFul API using Node js
http://adrianmejia.com/blog/2014/10/01/creating-a-restful-api-tutorial-with-nodejs-and-mongodb/
Then consume the same using following example.
MessageServiceData.getMessageService=function(){
var def = $q.defer();
$http.post("www.url.com", data)
.success(function(messages){
def.resolve(messages);
})
.error(function(messagesFail){
console.log('error:'+JSON.stringify(messagesFail));
def.reject([{"Error":JSON.stringify(messagesFail)}]);
});
return def.promise;
}

Save data into sql server using custom method in lightswitch html client

How to save data on button click(not by using save icon given by popup screen). I tried to use custom method like below. but data is not saving in sql database.
myapp.AddEditApplicantDeclaration.SubmitMethod_execute = funcation(scree)
{
msls.application.commitChanges().then(null, function fail(e) {
alert(e.message);
msls.application.cancelChanges();
throw e;
});
};
I created a button and write the _execute method. but its not saving into data base. Am i missing something here.
Its a simple table and trying to update isSummitted column into "Applicant" table.
I save the data by simply using myapp.commitChanges(); ... this can be included within validation under the _execute of a button as you have above

Upload csv file using javascript and d3

I am new to JavaScript and D3 and cannot figure out how to allow users to upload a csv file and displaying a scatterplot using d3. I am using the tag to allow user to select file. But I am not sure on what the next step should be. Is there a way to read the csv file and store it's contents in a d3 array and then displaying a graph using that array ??
Thanks in advance
Look into the d3.csv function (https://github.com/mbostock/d3/wiki/CSV). Here is a simple example
//load up the example.csv file
d3.csv('example.csv',
function(data){
//this is an object, the contents of which should
//match your example.csv input file.
console.log(data);
// do more stuff with 'data' related to
// drawing the scatterplots.
//
//-----------------------
},
function(error, rows) {
console.log(rows);
};
);
There are a number of examples online showing you how to go from a data array to a scatterplot...it's a matter of modifying those examples to fit your specific data format.

Adding MySQL requests to JS Code from JSFiddle

First and foremost, I want to say how amazing this community is. I've been reading and using this place for a bit now to get answers to a plethora of questions.
I'm currently working on building a student list (never really built a system before) system for our company using Bootstrap 3. I've got the meat of it worked out and have found this awesome JSFiddle by user Mils (many thanks) that does what I need it to in terms of adjusting data dynamically, which would be ideal for what we want.
http://jsfiddle.net/NfPcH/645/
My question is: how can I alter this so that it pulls data from a MySQL database I've created, and how do I alter it so that when adding/editing a row, it writes it to the db? I have a students.php page I created that pulls in the information as such:
// Prepare SQL Query
$STM = $db->prepare("SELECT `student_firstname`, `student_lastname`, `student_class`, `year` FROM students ORDER BY student_firstname");
// For executing prepared statement
$STM->execute();
// Fetch records
$STMrecords = $STM->fetchAll();
foreach($STMrecords as $row)
{
echo"<tr>";
echo"<td><a href='#' id='student-firstname' data-type='text' data-pk=".$row['student_firstname']."</td>";
echo"<td>".$row['student_lastname']."</td>";
echo"<td>".$row['student_class']."</td>";
echo"<td>".$row['year']."</td>";
echo"</tr>";
}
But this doesn't go hand-in-hand with the aforementioned JSFiddle, as it only posts the data on the page.
Thanks, everyone!
You need to redirect the get request in the JSFiddle to you php script. And the php script needs to return something on the expected format.
At the end of the fiddle there is a couple of mocks, there you can see how the output from the php script should be formatted.

Categories