动态占位符HTML表单(Dynamic placeholder HTML form)
我想根据选择的表单为我的html表单添加一个占位符。
<fieldset id="productEditPanel"> <legend>Edit a Product</legend> <form method="POST" action="/admin/api/prod/edit" enctype="multipart/form-data"> <label for="prodEditPId">Product *</label> <div> <select id="prodEditPId" name="pid" required> <option value="">Please select a product</option> {{#each prod}} <option value="{{pid}}">{{name}}</option> {{/each}} </select> </div> <!-- Design the form for editing a product's catid, name, price, description and image - the original values/image should be prefilled in the relevant elements (i.e. <input>, <select>, <textarea>, <img>) - prompt for input errors if any, then submit the form --> <label for="prodEditName">Name *</label> <div><input id="prodEditName" type="text" name="name" required pattern="^[\w- ']+$" /></div> <label for="prodEditPrice">Price *</label> <div><input id="prodEditPrice" type="number" step="0.05" name="price" required pattern="^\d+(?:\.\d{1,2})?$" /></div> <label for="prodEditDescription">Description</label> <div><textarea id="prodEditDescription" name="description" pattern="^[\w- ',\r\n]+$"></textarea></div> <label for="prodEditImage">Image *</label> <div><input id="prodEditImage" type="file" name="file" accept="image/*"> required /></div> <input type="submit" value="Add" /> </form> </fieldset>
我正在使用node.js,我对如何接收特定产品的特定数据感到困惑。
这是我的backend.js来处理select的开始时的数据检索:
app.get('/', function (req, res) { // async fetch data from SQL, render page when ready pool.query('SELECT * FROM categories', function (error, categories) { if (error) { console.error(error); res.status(500).end(); return; } pool.query('SELECT * FROM products', function (error, products) { if (error) { console.error(error); res.status(500).end(); return; } res.render('admin-panel', { layout: 'admin', title: 'IERG4210 Shop43 Admin', cat: categories.rows, prod: products.rows }); }); });
});
I want to add a placeholder to my html form based on a select of that form.
<fieldset id="productEditPanel"> <legend>Edit a Product</legend> <form method="POST" action="/admin/api/prod/edit" enctype="multipart/form-data"> <label for="prodEditPId">Product *</label> <div> <select id="prodEditPId" name="pid" required> <option value="">Please select a product</option> {{#each prod}} <option value="{{pid}}">{{name}}</option> {{/each}} </select> </div> <!-- Design the form for editing a product's catid, name, price, description and image - the original values/image should be prefilled in the relevant elements (i.e. <input>, <select>, <textarea>, <img>) - prompt for input errors if any, then submit the form --> <label for="prodEditName">Name *</label> <div><input id="prodEditName" type="text" name="name" required pattern="^[\w- ']+$" /></div> <label for="prodEditPrice">Price *</label> <div><input id="prodEditPrice" type="number" step="0.05" name="price" required pattern="^\d+(?:\.\d{1,2})?$" /></div> <label for="prodEditDescription">Description</label> <div><textarea id="prodEditDescription" name="description" pattern="^[\w- ',\r\n]+$"></textarea></div> <label for="prodEditImage">Image *</label> <div><input id="prodEditImage" type="file" name="file" accept="image/*"> required /></div> <input type="submit" value="Add" /> </form> </fieldset>
I'm using node.js and i'm confused on how to receive the specific data on the specific product.
This is my backend.js to handle the data retrieval at the start for the select:
app.get('/', function (req, res) { // async fetch data from SQL, render page when ready pool.query('SELECT * FROM categories', function (error, categories) { if (error) { console.error(error); res.status(500).end(); return; } pool.query('SELECT * FROM products', function (error, products) { if (error) { console.error(error); res.status(500).end(); return; } res.render('admin-panel', { layout: 'admin', title: 'IERG4210 Shop43 Admin', cat: categories.rows, prod: products.rows }); }); });
});
原文:https://stackoverflow.com/questions/28541534
最满意答案
虽然你没有提到你的查询应该做什么,但很难猜到。 您的问题的一般答案是“是的,您可以通过两个参数获得
GROUP BY
”。 这将创建遍历所有可能的a.id
和b.id
对的表。 这是你的问题的答案。现在,回到你的查询,这是错误的(只要你不解释你真正想用它做什么),因为按
a.id
分组将始终给出COUNT(a.id)
为0或1和DISTINCT
将仅为COUNT(a.id)
选择唯一值; 我怀疑这是预期的行为。编辑:使用新查询编辑问题后。 现在我觉得你根本不需要两个
GROUP BY
。 您正在多次计算每个事件,因为在加入categories
您会获得相同事件ID的多个记录。 你只需要有一个独特的计数:COUNT(DISTINCT e.PkID) .... GROUP BY " . $Group . "
While you don't mention what your query is supposed to do, it is hard to guess. The general answer to your question is "Yes, you can have
GROUP BY
by two parameters". This will create table going through all possible pairs ofa.id
andb.id
. This is the answer to your question.Now, returning to your query, it is just wrong (as long as you don't explain what you actually want to do with it) because grouping by
a.id
will always giveCOUNT(a.id)
as 0 or 1 andDISTINCT
will select only unique values forCOUNT(a.id)
; I doubt this is the expected behavior.EDIT: After the question has been edited with a new query. Now I think you don't need two
GROUP BY
at all. You are counting each event multiple times because when joining oncategories
you get multiple records for same event id. You simply need to have a distinct count:COUNT(DISTINCT e.PkID) .... GROUP BY " . $Group . "
相关问答
更多-
例如,你可以这样做: where (textField1Value == "" || textField1Value == attribute1) && (textField2Value == "" || textField2Value == attribute2) && (textField3Value == "" || textField3Value == attribute3) You could, for example, do like: where (textField1Value == "" ...
-
有更好的方法,但这应该工作: SELECT CASE WHEN f.Name IN ('FacultyName1', 'FacultyName2', 'FacultyName3') THEN 'FacultyGroup1' WHEN f.Name IN ('FacultyName4', 'FacultyName5') THEN 'FacultyGroup2' END AS FacultyGroup, COUNT(*) AS Students FROM ...
-
写道: ;WITH cte AS ( SELECT AgentId, CAST('
' + REPLACE(States, ',', ' ') + ' ' AS XML) AS States, CAST('' + REPLACE(Products, ',', ' ') + ' ' AS XML) AS Products FROM @tbVendor ) ,FinalList AS ( SELECT ... -
从2个表中分组2个参数(Group by 2 parameters from 2 tables)[2023-05-17]
虽然你没有提到你的查询应该做什么,但很难猜到。 您的问题的一般答案是“是的,您可以通过两个参数获得GROUP BY ”。 这将创建遍历所有可能的a.id和b.id对的表。 这是你的问题的答案。 现在,回到你的查询,这是错误的(只要你不解释你真正想用它做什么),因为按a.id分组将始终给出COUNT(a.id)为0或1和DISTINCT将仅为COUNT(a.id)选择唯一值; 我怀疑这是预期的行为。 编辑:使用新查询编辑问题后。 现在我觉得你根本不需要两个GROUP BY 。 您正在多次计算每个事件,因为在加 ... -
从一个表中分组多行?(Group multiple rows from one table?)[2022-05-14]
这两种技术都有其优点,答案可以基于观点; 我的是。 我建议在图像表中添加字段(例如cover ),指示图像是否为主图像。 大多数行在cover字段中具有NULL值是可以的。 在imageid和cover上创建索引。 我还建议创建一个名为CoverImages的视图,该视图select ... from images where cover=true以便任何只需要封面图像的应用程序都可以直接使用此视图。 根据您的数据库引擎,您可以创建稀疏列和/或创建筛选索引。 另一个选项是为具有projectid和image ... -
在SQL Server Management Studio对象浏览器中分组SQL表(Group SQL tables in SQL Server Management Studio object explorer)[2024-01-29]
在SQL Server 2008中,您可以将过滤器应用到对象资源管理器视图。 找到Filter按钮并点击它 定义您的过滤器 - 可以通过对象名称和/或模式进行过滤 您的对象的过滤视图: In SQL Server 2008, you can apply filters to your object explorer views. Find the Filter button and click on it Define your filter - filtering by object name and/o ... -
如果您不关心journal ,请不要选择它,它会分割您的结果。 此外,普通过滤器需要放在WHERE子句中,而不是HAVING子句: SELECT author.name, COUNT(*) FROM author INNER JOIN author_has_publication ON author.idAuthor = author_has_publication.Author_idAuthor INNER JOIN publication ON author_has_public ...
-
从多个表中分组数据(Grouping data from multiple tables)[2023-05-15]
使用UNION ALL。 它提供了比UNION更好的性能,无论如何在这种情况下删除重复都是错误的。 您还可以在将所有表放在一起后执行GROUP BY,以便可以跨表对行进行分组。 这将为您提供所有4个表中相同持续时间的行计数。 select everything.duration, count(*) from ((select TIMESTAMPDIFF(hour,startTime,endTime) as duration from feb where type='gen') union all ( ... -
在您的表的详细信息行下方的表格中添加一行。 然后在每个组的所有数据之后重复这一行。 然后,您可以将子报告放入此行,它将显示在每个组的末尾。 Add a row into your table underneath the details row for your group. This one row will then be repeated after all your data for each group. You can then put your sub-report into this row ...
-
你尝试过类似的东西吗? @exams = Exam.joins(exam_subjects: :subject).where(:id => [params[:exam_id], params[:subject_id]]) ? Have you tried something like @exams = Exam.joins(exam_subjects: :subject).where(:id => [params[:exam_id], params[:subject_id]]) ?