0

I have a database with the following table:

Product_table

The product table has 3 columns; product_name, product_info, and product_cost

I need to query the database in order to pull all product names out, and put them in an array.

I know the SQL is 'SELECT product_name FROM product_table' but I don't know how to implement that in javascript.

Any guidance would be greatly appreciated

1

1 Answer 1

0

Edit: See here if it helps: Is it possible to access an SQLite database from JavaScript?

Your question is very badly asked.

I suggest you to use node.js: https://nodejs.org/en/download/ It allows you to run javascript without browser.

And I assume the database is MySQL. Then u will need the mysql package: https://github.com/mysqljs/mysql Refer the github documentation on how to install and use it.

Basically, you will use the mysql pacakge to make connection to your database (you need to provide the host/user/password), create database connection, then executes your SELECT query. The mysql package's conn.query(sql, params) already returns list of results in an array for you.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, I appreciate your input. This is all pretty new to me. I am using SQLite3 and the database connection is defined in my Django settings.py file. This script runs on the 'index.html' page. I am pretty sure that the connection does not need to be defined in the script because it is already defined in the settings...correct me if I am wrong
that is an entirely different technology stack you are using. please specify it in your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.