首页 \ 问答 \ 动态占位符HTML表单(Dynamic placeholder HTML form)

动态占位符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
更新时间:2022-05-25 09:05

最满意答案

虽然你没有提到你的查询应该做什么,但很难猜到。 您的问题的一般答案是“是的,您可以通过两个参数获得GROUP BY ”。 这将创建遍历所有可能的a.idb.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 of a.id and b.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 give COUNT(a.id) as 0 or 1 and DISTINCT will select only unique values for COUNT(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 on categories you get multiple records for same event id. You simply need to have a distinct count:

COUNT(DISTINCT e.PkID) .... GROUP BY " . $Group . "

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)