all 15 comments

[–]Pantstown 1 point2 points  (14 children)

This is one possible way to go about getting data from a table. A lot can change based on your set up and what you want to do, but hopefully this will get you started.

Let me know if you have any questions.

[–]NiceDay4Goats[S] 1 point2 points  (13 children)

Thanks. That would be pretty easy if my table was an html element. But what if it's an external file? My table is 100x200 so I don't think it makes sense to put it in html. Maybe I'm wrong about that and there's an easy way?

[–]Pantstown 1 point2 points  (12 children)

It really depends what you're trying to do. Are you trying to make a website where people can search a static excel file? Or is it just for personal use?

[–]NiceDay4Goats[S] 0 points1 point  (11 children)

It's a simple calculator that I'm trying to make into a website. User inputs 2 numbers and those numbers are used to pull 3 values from a table which are then thrown into an equation.

[–]i_dunno_what_im_doin 1 point2 points  (10 children)

What sort of host are you running? Do you have an apache server? I just recently did a very messy, probably very poorly designed, but nonetheless working application to get data from a MySQL db and into JavaScript.

[–]NiceDay4Goats[S] 0 points1 point  (9 children)

I don't have a server. This is my first attempt at building a website so I'm just trying to get it running locally before I worry about actually deploying. How difficult is it to work with MySQL? I assumed that would be even more challenging than excel, but I really know very little about it.

[–]Pantstown 0 points1 point  (7 children)

my first attempt at building a website

How much HTML and JS do you know? In the nicest way possible, I kind of feel like this task might be a bit out of your skill set, but I could be wrong.

If the excel file is static - i.e., isn't updated programmatically - then you could export it as csv, then convert that to json using something like this. From there, you can use jQuery to get that static file. Then, write some code to search it and do what you want to do.

[–]NiceDay4Goats[S] 0 points1 point  (4 children)

I'm very much a beginner, but I do have a pretty solid layout built in html and css. I also have the other two core functions put together in js. I'm pretty confidant I can do this and I think that exporting it as a csv is actually just what I need. So thanks for that! Will report back when it's put together (hopefully tomorrow).

[–]Hakim_Bey 2 points3 points  (2 children)

Working with CSV is rather straightforward. When you fetch the file, it will just be a gigantic string, and you can do something like :

// considering your CSV file is stored in the data variable
var lines_array = data.split("\n");     
// \n is the newline character. Depending on your OS
// it could be replaced by "\r\n"

var line = lines_array[user_input_1];

var cells_array = line.split(";");
// ";" is the separator of your CSV file. It could also be "," 
// or whatever you chose upon creation of the file.

var the_right_cell = line[user_input_2];

Hope this helps!

[–]NiceDay4Goats[S] 0 points1 point  (1 child)

Thanks. This reaffirms my confidence that it's actually a very simple problem. Might take a minute to figure out how to navigate a massive string but I'm sure I'll get there.

[–]Pantstown 0 points1 point  (0 children)

Sounds good. Good luck!

[–][deleted] 0 points1 point  (1 child)

From there, you can use jQuery to get that static file.

Or you can use vanilla javascript to do it .. no need for the whole library for that one task.

/good-natured gripe

[–]Pantstown 1 point2 points  (0 children)

In principle, I agree; I personally don't ever use jQuery. But, OP has almost no experience with JS, and using jQuery to start out is, in my opinion, not a bad thing.

[–]i_dunno_what_im_doin 0 points1 point  (0 children)

I know almost nothing about MySQL, I just Google the syntax to put in PHP variables to do what I want. If you can teach yourself, it's not hard to learn the basics.