CREATE TEMPORARY TABLE temp_table AS
SELECT printer,
CONCAT('{', GROUP_CONCAT(QUOTE(materials)), '}') AS materials
FROM printers
GROUP BY printer;
SELECT CONCAT('{"printer":"', printer, '", "materials":', materials, '}') AS json_format
FROM temp_table;
DROP TEMPORARY TABLE IF EXISTS temp_table;
{"printer":"Принтер цвет", "materials":{'A4','A4color','610*175m','610*50m','914*175m','914*50m','A3','A3color'}}
{"printer":"Принтер ч/б", "materials":{'A3','A4'}}
{"printer":"Принтер ч/б и цвет", "materials":{'610*175m','610*175m','914*175m','914*50m'}}
http://sql-tutorial.ru/ru/content.html
https://www.sql-ex.ru/?Lang=0
document.getElementById('id').value
, потом что в document.getElementById('id')
, если в value пусто.выводит новую формуВангую, что в итоге у вас куча одинаковых форм и, соответственно, куча инпутов с
id="id"
, что, естественно, недопустимо. // Get form element
const form = document.querySelector('form');
// Implementation DRY principe, write repeated code into function
const httpRequest = (url, options) => fetch(url, options)
.then(response => response.json())
.then(console.log)
.catch(console.error);
// Create post request options
const postOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};
// Create get request options
const getOptions = {
method: 'get',
headers: {
'Content-Type': 'application/json',
}
};
// Create post request function
const postRequest = data => httpRequest('http://:3000/info/', {
...postOptions,
body: JSON.stringify(data)
});
// Create get request function
const getRequest = _ => fetch('http://:3000/info/', getOptions)
.then(response => response.json())
.then(console.log)
.catch(console.error);
// Create form handler
const formHandler = (e) => {
// End handler after request
e.preventDefault();
// Get data from form
const data = Object.fromEntries(new FormData(e.target).entries());
// Send post request
postRequest(data);
// Send get request
getRequest();
form.classList.remove('open');
popup.classList.remove('popup_open');
}
// Set form handler
form.addEventListener('submit', formHandler);