Created
May 2, 2017 19:00
-
-
Save eroberer/e82c1022e1c1dbd0ba0e8cc66a8a3325 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getProducts(categoryId){ | |
let results; | |
connection.query('SELECT * FROM products WHERE category = ?', [categoryId], | |
function (error, products, fields) { | |
if (error) throw error; | |
for(let i = 0; i < products.length; i++){ | |
connection.query('SELECT image FROM productimages WHERE productID = ?', [products[i].productID], | |
function (error2, images, fields2){ | |
if (error2) throw error2; | |
products[i].images = images; | |
}); | |
connection.query('SELECT * FROM optionsofproduct as op, productoptions as po WHERE op.productID = ? AND op.optionID = po.optionID', [products[i].productID], | |
function (error2, options, fields2){ | |
if (error2) throw error2; | |
products[i].options = options; | |
}); | |
} | |
results = products; | |
}); | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment