Skip to content

Instantly share code, notes, and snippets.

@eroberer
Created May 2, 2017 19:00
Show Gist options
  • Save eroberer/e82c1022e1c1dbd0ba0e8cc66a8a3325 to your computer and use it in GitHub Desktop.
Save eroberer/e82c1022e1c1dbd0ba0e8cc66a8a3325 to your computer and use it in GitHub Desktop.
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